我有一个根 urls.py 和一个应用程序 urls.py。在我的根目录中,我有这个:
from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^$', include('realestate.properties.urls')),
(r'^admin/', include(admin.site.urls)),
)
在我的应用程序网址中,我有以下内容
from django.conf.urls.defaults import *
urlpatterns = patterns('realestate.properties.views',
url(r'^$', 'property_list', {'template_name': 'properties/property_list.html'}, name='property_list'),
url(r'^(?P<slug>[-\w]+)/$', 'property_detail', { 'template': 'property_detail.html' }, name='property_details'),
)
现在在我的模板中有一个指向详细信息 View 的链接,如下所示:
{% url property_details property.slug %}
每次我渲染这个页面我都会得到错误:
*在呈现时捕获 NoReverseMatch:使用参数“(u'111-front-st',)”和关键字参数“{}”找不到“property_details”的反向。*
无论我做什么,我都会收到该错误。我尝试只捕获 id 但没有任何效果,我不确定为什么,我以前多次使用过 url,所以如果我遗漏了一些明显的东西,我真的很困惑。看到这里有什么问题吗?
谢谢
杰夫
最佳答案
我认为您需要从您的 urlconf 中删除 $
,其中包含应用程序的 url。也许您也可以删除 ^
。
urlpatterns = patterns('',
(r'^', include('realestate.properties.urls')),
(r'^admin/', include(admin.site.urls)),
)
http://docs.djangoproject.com/en/1.2/topics/http/urls/#including-other-urlconfs
Note that the regular expressions in this example don't have a $ (end-of-string match character) but do include a trailing slash. Whenever Django encounters include(), it chops off whatever part of the URL matched up to that point and sends the remaining string to the included URLconf for further processing.
关于python - 这个网址有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4915647/