I have problem when I visit localhost:8000/home
:
Powershell: django.urls.exceptions.NoReverseMatch: Reverse for 'register' not found. 'register' is not a valid view function or pattern name.
html:
<section>
<nav >
<!-- Container wrapper -->
<div >
<!-- Navbar brand -->
<a href="{% url 'home_page' %}"> Turbine Power Web</a>
<div id="navbarResponsive">
<ul >
{% if user.is_authenticated %}
<li ><a href="{% url 'accounts:logout' %}">Logout</a></li>
<li ><a href="{% url 'accounts:password_change' %}">Change Password</a></li>
{% else %}
<li ><a href="{% url 'accounts:login' %}">Login</a></li>
<li ><a href="{% url 'accounts:user-registration' %}">Register</a></li>
{% endif %}
<li ><a href="">Turbine Models</a></li>
<li ><a href="">Author</a></li>
{% if user.is_company %}
<li ><a href="">My Models</a></li>
{% endif %}
<li > Hello, {{ user.username|default:'Guest' }} </li>
</ul>
</div>
</div>
</nav>
<!-- Navbar -->
</section>
views.py
def home_page(request):
return render(request, 'turbineweb/home_page.html')
project urls.py
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('accounts.urls', namespace='accounts')),
path('', include('turbineweb.urls')),
accounts urls.py
app_name = 'accounts'
urlpatterns = [
path('login/', CustomLoginView.as_view(redirect_authenticated_user=True, template_name='accounts/login.html',
authentication_form=LoginForm), name='login'),
path('logout/', auth_views.LogoutView.as_view(template_name='accounts/logout.html'), name='logout'),
path('registration/', RegisterView.as_view(), name='users-registration'),
path('password-change/', ChangePasswordView.as_view(), name='password_change'),
path('password_reset/', auth_views.PasswordResetView.as_view(), name='password_reset'),
path('password_reset/done/', auth_views.PasswordResetDoneView.as_view(), name='password_reset_done'),
path('reset/<uidb64>/<token>/', auth_views.PasswordResetConfirmView.as_view(), name='password_reset_confirm'),
path('reset/done/', auth_views.PasswordResetCompleteView.as_view(), name='password_reset_complete'),
]
turbineweb urls.py
app_name = 'turbineweb'
urlpatterns = [
path('home/', views.home_page, name='home_page'),
]
CodePudding user response:
You made a typo, it is users-registration
and not user-registration
:
<li ><a href="{% url 'accounts:users-registration' %}">Register</a></li>