我正在Book应用程序中构建一个Django模板,并使用URL标记重定向到Account应用程序的URL。但上面写着account' is not a registered namespace
。你知道吗
书本.url:
app_name = 'book'
urlpatterns = [
path('', views.HomePageView.as_view(), name='home'),
path('account/', include('account.urls', namespace='account'))
]
书本视图:
class HomePageView(generic.TemplateView):
template_name = 'book/home.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['all_books'] = Book.objects.all()
return context
模板/书籍/主页.html:
<div id="register">
<p>
<a href="{% url 'account:register' %}"> Sign Up </a>
</p>
</div>
帐户/url:
app_name='account'
urlpatterns=(
path('register/', views.RegisterView.as_view(), name='register'),
path('successful/', views.successful_created, name='successful'),
)
我相信如果您删除namespace=account并只使用path('account/',include('帐户.url)会很好的。你知道吗
您面临的问题主要是因为您正试图从
book
app定义account
app。你需要做的是在与
settings.py
位于同一目录下的主项目urls.py
中,添加book和accountapp。你知道吗现在你的书本.url将显示:
帐户/url将显示:
相关问题 更多 >
编程相关推荐