0

I have a view

@login_required
def dashboard(request):
    if request.session.get("pending-token"):
        return redirect("speaker_create_token",
                        request.session["pending-token"])
    return render(request, "dashboard.html")

and a row in urls.py

url(r'^dashboard/', dashboard, name='dashboard'),

When I open /dashboard/ with logged user, I see page. My html code is for authentication is

<div>
    <div id="user">

        {% if user.is_authenticated %}
            <snap><a href="{% url 'profile' %}">{{ user.username }}</a> </snap>
            <snap><a href="{% url 'logout' %}">Logout</a> </snap>
        {% else %}
            <snap><a href="{% url 'login' %}">Sign In</a> </snap>
            <snap><a href="{% url 'create_user' %}">Sign Up</a> </snap>
        {% endif %}

    </div>
</div>

When I try to request /dashboard/ without logging I get the error

NoReverseMatch at /dashboard/

Reverse for 'account_login' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

I added LOGIN_URL = '/accounts/login/' to settings.py, but it does not work. I saw similar questions, but I still can not understand how to avoid this error.

Antonina
  • 604
  • 1
  • 5
  • 16
  • 1
    None of the code you're showing is trying to use an `account_login` url – Sayse Dec 13 '16 at 13:18
  • 1
    Possible duplicate of [What is a NoReverseMatch error, and how do I fix it?](http://stackoverflow.com/questions/38390177/what-is-a-noreversematch-error-and-how-do-i-fix-it) – Sayse Dec 13 '16 at 13:19
  • I don't use `account_login` url in code, so I can not understand why it notes in the error. – Antonina Dec 13 '16 at 13:28
  • I think you are being redirected to the `account_login` url because you use `@login_required`, and if you are not logged in Django tries to redirect to your login page. – elethan Dec 13 '16 at 13:34
  • So do I need rename `login` to `account_login` in url? – Antonina Dec 13 '16 at 13:41

0 Answers0