如何配置Django网址解析,使除somedomain.com/admin
以外的所有其他网址指向应用程序而不添加任何前缀?
在我的项目urls.py中,我有
from django.conf.urls import patterns, include, url
from django.contrib import admin
urlpatterns = patterns('',
url(r'^$', include("photoapp.urls", namespace="photoapp")),
url(r'^admin/', include(admin.site.urls)),
)
在photoapp/urls.py
,我有
from django.conf.urls import patterns, url
from . import views
urlpatterns = patterns('',
url(r'^$',views.index),
url(r'^fileUpload/?$', views.file_upload)
)
现在,这两个网址都在photoapp/views.py
内有关联的观点。 somedomain.com
加载views.index
指定的模板,但somedomain.com/fileUpload
返回404.具体而言,错误消息说明
Using the URLconf defined in project.urls, Django tried these URL
patterns, in this order:
^$
^admin/
我的目标是
somedomain.com/admin
解析为管理员应用,
somedomain.com
somedomain.com/fileUpload
somedomain.com/search?q=query
由photoapp/urls.py
处理。如何配置应用程序urls.py呢?
答案 0 :(得分:2)
从第一个网址中删除$
个符号:
url(r'^', include("photoapp.urls", namespace="photoapp")),