Django==3.0.8
django-comments-xtd==2.6.2
views.py
@csrf_protect
@login_required
def like(request, comment_id, next=None):
"""
Like a comment. Confirmation on GET, action on POST.
Templates: :template:`django_comments_xtd/like.html`,
Context:
comment
the flagged `comments.comment` object
"""
comment = get_object_or_404(get_comment_model(), pk=comment_id,
site__pk=get_current_site_id(request))
if not get_app_model_options(comment=comment)['allow_feedback']:
ctype = ContentType.objects.get_for_model(comment.content_object)
raise Http404("Comments posted to instances of '%s.%s' are not "
"explicitly allowed to receive 'liked it' flags. "
"Check the COMMENTS_XTD_APP_MODEL_OPTIONS "
"setting." % (ctype.app_label, ctype.model))
# Flag on POST
if request.method == 'POST':
perform_like(request, comment)
return next_redirect(request,
fallback=next or 'comments-xtd-like-done',
c=comment.pk)
# Render a form on GET
else:
flag_qs = comment.flags.prefetch_related('user')\
.filter(flag=LIKEDIT_FLAG)
users_likedit = [item.user for item in flag_qs]
return render(request, 'django_comments_xtd/like.html',
{'comment': comment,
'already_liked_it': request.user in users_likedit,
'next': next})问题
当匿名用户按下“相似”按钮时,它们将被重定向到http://localhost:8000//login/?next=/%5Ecomments/like/3/。
我希望它被重定向到http://localhost:8000//login/
在settings.py LOGIN_URL中,缺席。
我不知道这个管理/登录来自哪里。接下来我能试试什么?
发布于 2020-07-30 09:28:43
在您的INSTALLED_APPS中,在settings.py中,如果django.contrib.auth高于您的应用程序,DJANGO将呈现默认的auth,所以您应该做的是将应用程序置于django.contrib.auth之上,以便DJANGO首先呈现您的应用程序。
对我来说很管用
https://stackoverflow.com/questions/63169332
复制相似问题