gpt4 book ai didi

python - Django SimpleLazyObject

转载 作者:太空狗 更新时间:2023-10-29 22:11:28 29 4
gpt4 key购买 nike

当我尝试提交时,出现类型错误:

int() argument must be a string or a number, not 'SimpleLazyObject'

我的观点.py:

def bookmark_save_page(request):
if request.method == 'POST':
form = BookmarkSaveForm(request.POST)
if form.is_valid():
# Create or get link.
link, dummy = Link.objects.get_or_create(
url=form.cleaned_data['url']
)
# Create or get bookmarks.
bookmark, created = Bookmark.objects.get_or_create(
user = request.user,
link = link
)
# Update bookmark title.
bookmark.title = form.cleaned_data['title']
# If the bookmark is being updated, clear old tag list.
if not created:
bookmark.tag_set.clear()
# Create new tag list.
tag_names = form.cleaned_data['tags'].split()
for tag_name in tag_names:
tag, dummy = Tag.objects.get_or_create(name=tag_name)
bookmark.tag_set.add(tag)
# Save bookmark to database.
bookmark.save()
return HttpResponseRedirect(
'/user/%s/' %request.user.username
)
else:
form = BookmarkSaveForm()

variables = RequestContext(request, {'form': form})
return render_to_response('bookmark_save.html',variables)

请指导我。谢谢。

最佳答案

request.user,默认类型为SimpleLazyObject。要解决它,

bookmark, created = Bookmark.objects.get_or_create(
user = request.user,
link = link
)

应该是

bookmark, created = Bookmark.objects.get_or_create(
user = request.user.id,
link = link
)

如果这不能解决问题,请确保您已登录。

关于python - Django SimpleLazyObject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17623234/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com