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>
Use this:
<a href="{% url 'login:login' %}"><h3 class="agileinfo_sign">Sign In </h3></a>
Hope this small change will solve your problem.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With