【发布时间】:2019-02-01 01:03:13
【问题描述】:
我正在 Book 应用程序中构建一个 Django 模板,并使用 URL 标签重定向到 Account 应用程序的 URL。但上面写着account' is not a registered namespace。
book.urls:
app_name = 'book'
urlpatterns = [
path('', views.HomePageView.as_view(), name='home'),
path('account/', include('account.urls', namespace='account'))
]
book.views:
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
templates/book/home.html:
<div id="register">
<p>
<a href="{% url 'account:register' %}"> Sign Up </a>
</p>
</div>
帐户/网址:
app_name='account'
urlpatterns=(
path('register/', views.RegisterView.as_view(), name='register'),
path('successful/', views.successful_created, name='successful'),
)
【问题讨论】: