我正在運行一個使用Django 1.8的基本項目,我不確定我是否在文檔中丟失了某些內容或者只是誤解了它。Django 1.8無法使用多個url conf文件匹配url模式
我在urls.py
上遇到了識別正確網址格式的問題。 我使用This section of the Django documentation作爲例子。
我的項目目錄結構:
integrations
|--integrations
|--- migrations
|-- ....
|-- __init__.py
|-- admin.py
|-- models.py
|-- settings.py
|-- urls.py
|-- views.py
|-- wsgi.py
|-- templates
|-- ....
|-- manage.py
具體來說,urls.py
內容是:
from django.conf.urls import include, url
from django.contrib import admin
from . import views
urlpatterns = [
url(r'^wsa/', views.index, name='index'),
url(r'^(?P<customer_id>[0-9]+)/$', views.address_detail, name='address_detail'),
url(r'^admin/', include(admin.site.urls)),
]
正如你所看到的,我已經列爲本文件的URL模式wsa
。基於上面提到的文檔時,這應該被消除和代替是url(r'^$', views.index, name='index'),
的文檔還示出了具有不同的目錄結構,這似乎是在根目錄一起manage.py
根urls.py
。這是文件指出我會把我的wsa
模式,幷包括在兒童urls.py
;然而,當我這樣做,該文件不會被讀取,而不是我的URL模式開始失效:
Using the URLconf defined in integrations.urls, Django tried these URL patterns, in this order:
^$ [name='index']
The current URL, wsa/, didn't match any of these.
Corrosponding導致失敗url.py文件:
urls.py:
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^wsa/', include('integrations.urls')),
url(r'^admin/', include(admin.site.urls)),
]
integrations \ urls.py:
from django.conf.urls import include, url
from django.contrib import admin
from . import views
urlpatterns = [
url(r'^$', 'views.index', name='index'),
]
我在想什麼?
我想我錯過了什麼 - 謝謝 –