I am receiving the following error: "File "C:\Users\odesm\anaconda3\envs\adb3\lib\site-packages\django\urls\base.py", line 83, in reverse raise NoReverseMatch("%s is not a registered namespace" % key) django.urls.exceptions.NoReverseMatch: 'accounts' is not a registered namespace"
I have reviewed similar errors on stack overflow and attempted their solutions but none of them seem applicable. I do not understand in what manner I have failed to register the namespace when it has been specified in the path(include(namespace="")) and I have included the app_name="app_name" in the corresponding url.py file.
base.html (the snippet throwing the error)
<li class="nav-item">
<a class="nav-link" href="{% url 'accounts:login' %}">Login</a>
</li>
urls.py (under a sitemanger app)
app_name = 'sitemanager'
urlpatterns = [
path('', views.HomeView.as_view(), name='site-home'),
path('accounts/', include('accounts.urls', namespace='accounts')),
path('accounts/', include('django.contrib.auth.urls')),
]
urls.py (for the accounts app)
app_name = 'accounts'
urlpatterns = [
path('login/', auth_views.LoginView.as_view(template_name='accounts/login.html'), name='login'),
path('logout/', auth_views.LogoutView.as_view(template_name='accounts/logout.html'), name='logout'),
path('signup/', views.SignUpView.as_view(template_name='accounts/signup.html'), name='signup'),
path('edit/', views.UpdateProfileView.as_view(template_name='accounts/update_profile.html'), name='edit'),
path('<slug:username>/', views.ProfileView.as_view(template_name='accounts/profile.html'), name='profile')
]
To me, it appears I have registered the proper namespace but it seems my logic is at fault somewhere.
Since I have the urls.py for the accounts app included inside the urls.py for my sitemanager app, I needed to route through sitemanager as well.
Ergo the following
<li class="nav-item">
<a class="nav-link" href="{% url 'accounts:login' %}">Login</a>
</li>
Needs to become
<li class="nav-item">
<a class="nav-link" href="{% url 'sitemanager:accounts:login' %}">Login</a>
</li>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.