Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django error: Reverse for '...' not found. '...' is not a valid view function or pattern name

It gives the error: Reverse for 'login' not found. 'login' is not a valid view function or pattern name.

urls.py:

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('App.urls')),
    path('accounts/', include(('django.contrib.auth.urls', 'django.contrib.auth'), namespace='login')),
    path('accounts/', include('Account.urls')),
] 

index.html:

<a href="{% url 'login' %}"><h3 class="agileinfo_sign">Sign In </h3></a>
like image 706
Athif Saheer Avatar asked Nov 06 '25 13:11

Athif Saheer


2 Answers

Use this:

<a href="{% url 'login:login' %}"><h3 class="agileinfo_sign">Sign In </h3></a>

Hope this small change will solve your problem.

like image 114
Mubashar javed Avatar answered Nov 08 '25 09:11

Mubashar javed


In my case, it happened to me when I forgot to add the login_url = 'view_name' field of login_required() decorator.

before:

@login_required()
def checkout_page(request):
    return render(request, 'checkout.html', context)

after:

@login_required(login_url='your_login_view_name')
def checkout_page(request):
    return render(request, 'checkout.html', context)

I hope this can help someone who wants only authenticated users can access the checkout page.

like image 33
Parvana Avatar answered Nov 08 '25 10:11

Parvana