1
我決定在我的項目的根目錄下有主頁面和'關於我'頁面等頭版,而不是其他應用。這意味着該項目是這樣的:Django根項目url命名空間不起作用
/django-helloworld
/Hello_World
__init__.py
url.py
views.py
wsgi.py
/static
style.css
/templates
index.html
我的urls.py看起來是這樣的:
from django.conf.urls import url, include
from django.contrib import admin
from . import views
app_name = 'Hello_World'
urlpatterns = [
url(r'^$', views.IndexView.as_view(), name='index'),
url(r'^admin/', admin.site.urls),
的問題是,當我嘗試指向我的模板的URL,它的工作原理是這樣做:
<a href="{% url 'index' %}">Home</a>
但如果我嘗試引用的命名空間,如下所示:
<a href="{% url 'Hello_World:index' %}">Home</a>
我得到這個錯誤:
NoReverseMatch at/
'Hello_World' is not a registered namespace
我在做什麼錯?提前致謝。
是你的'ROOT_URLCONF'嗎? – knbk
@knbk你到底在說什麼?在settings.py我有'ROOT_URLCONF ='Hello_World.urls'' –