我认为这是一个长时间盯着代码的情况,但我无法解析此URL。我正在使用Django 1.5.5。
这是主urls.py
:
from django.conf.urls import patterns, include, url
from django.views.generic import RedirectView
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^$', RedirectView.as_view(url='/swap/')),
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^swap/$', include('apps.swap.urls')),
url(r'^admin/swap/', include('apps.swap.admin_urls')),
url(r'^admin/', include(admin.site.urls)),
)
这是我的应用url.py
:
from django.conf.urls import patterns, url
from apps.swap.views import About
urlpatterns = patterns('apps.swap.views',
url(r'^$', 'index'),
url(r'^about/$', About.as_view()),
)
除/swap/
外,所有网址均已解析(包括/swap/about/
)。它只是拒绝解决。这就是我所看到的:
Using the URLconf defined in urlconf, Django tried these URL patterns, in this order:
1. ^__debug__/sql_select/$ [name='sql_select']
2. ^__debug__/sql_explain/$ [name='sql_explain']
3. ^__debug__/sql_profile/$ [name='sql_profile']
4. ^__debug__/template_source/$ [name='template_source']
5. ^$
6. ^admin/doc/
7. ^swap/$
8. ^admin/swap/
9. ^admin/
The current URL, swap/about/, didn't match any of these.
我在这里缺少什么?我知道它必须是简单的东西,但昨晚经过16个小时编码弯曲后,我想我已经失明了。
答案 0 :(得分:4)
url(r'^swap/$', include('apps.swap.urls'))
最后$
是坏男孩。它匹配字符串的结尾,因此显然拒绝swap/about
。