djangodjango-comments

Wrong: /admin/login/, Expected: /accounts/login/


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})

Problem

When an incognito user presses a like button, they are redirected to http://localhost:8000/admin/login/?next=/%5Ecomments/like/3/

I expect it to be redirected to http://localhost:8000/accounts/login/

In settings.py LOGIN_URL is absent.

I am not sure where this admin/login comes from. What can I try next?


Solution

  • In your INSTALLED_APPS,in settings.py, If django.contrib.auth is above your app, DJANGO will render the default auth , So what you should do is place your app above the django.contrib.auth so that DJANGO will render yours first.

    That works for me