Reputation: 15
I am making a website based on William S. Vincent's "Django for Beginners." In the project I am building I have a homepage, with a drop-down menu that includes, among other options, a "Change Password" selection. When I go directly to the URL 127.0.0.1:8000/users/password_change/
, I arrive at the correct page, but clicking the "Change Password" option gives me the following error:
"Using the URLconf defined in newspaper_project.urls Django tried these URL patterns in this order: 1. admin/ 2. users/signup/ [name='signup'] 3. users/login/ [name='login']...11. articles/ 12. [name='home']. The current path, users/password_change/{% url 'password_change' %}. didn't match any of these."
Below are the relevant sections of code:
# /Desktop/news/templates/base.html
{% if user.is_authenticated %}
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link dropdown-toggle" href="#" id="userMenu"\
data-toggle="dropdown" aria-haspopup="true" aria-expanded\
="false">
{{ user.username }}
</a>
<div class="dropdown-menu dropdown-menu-right"\
aria-labelledby="userMenu">
<a class="dropdown-item" href="{% url 'article_list' %}">Entries</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="{% url 'password_change'
%}">Change password</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="{% url 'logout' %}">
Log Out</a>
# /Desktop/news/users/urls.py
from django.urls import path
from .views import SignUpView
urlpatterns = [
path('signup/', SignUpView.as_view(), name='signup'),
]
# /Desktop/news/users/views.py
from django.shortcuts import render
from django.urls import reverse_lazy
from django.views.generic import CreateView
from .forms import CustomUserCreationForm
class SignUpView(CreateView):
form_class = CustomUserCreationForm
success_url = reverse_lazy('login')
template_name = 'signup.html'
# /Desktop/news/newspaper_project/urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('users/', include('users.urls')), #new
path('users/', include('django.contrib.auth.urls')), #new
path('articles/', include('articles.urls')), #new
path('', include('pages.urls')), #new
]
The 'article_list' and 'logout' buttons as specified in base.html
work, and I can access password_change by directly typing in 127.0.0.1:8000/users/password_change/
, but clicking the button gives me the error as described above. I would appreciate a solution to this issue as well as any explanation as to why this issue occurs.
Upvotes: 0
Views: 1362
Reputation: 599628
Your password_change url tag is spread across two lines, so Django doesn't recognise it as a template tag. Make sure it is all in one line.
<a class="dropdown-item" href="{% url 'password_change' %}">Change password</a>
Upvotes: 1