aaa*_*210 2 django url-routing django-urls django-apps
I am trying to include a Django sub-app's urls into the main urls.py.
app/urls.py:
urlpatterns = patterns(
'',
...
include('transfers.urls'),
)
Run Code Online (Sandbox Code Playgroud)
app/transfers/urls.py:
urlpatterns = patterns(
'',
url(r'^transfers/$', 'some.view'),
...
)
Run Code Online (Sandbox Code Playgroud)
But I get a route not found error. The last element of the route is just the URLconf module from the sub-app. It has not been delisted into the parent URL list.
Using the URLconf defined in app.urls, Django tried these URL patterns, in this order:
1.
2.
...
30. <module 'transfers.urls' from '/path/to/app/transfers/urls.pyc'>
The current URL, transfers/, didn't match any of these.
Run Code Online (Sandbox Code Playgroud)
When I copy the first URL pattern from transfers.urls into the main urls.py, it works. I seems to be including the sub-app urls.py, but I am not sure if in the right way.
How can I get this to work properly?
You can try like this:
url(r'^transfers/', include('transfers.urls', namespace="transfers")),
Run Code Online (Sandbox Code Playgroud)
Then you can use host:port/transfers/transfers/.
These two transfers are different. The first one is the one in app/urls.py, and the second one is the one in app/transfers/urls.py.
| 归档时间: |
|
| 查看次数: |
1008 次 |
| 最近记录: |