我对 SiteTree 配置中的 URL 模式有疑问。我已阅读手册:https ://django-sitetree.readthedocs.org/ru/latest/quickstart.html
所以我试图用命名的 URL 制作我的树:
应用程序/urls.py:
urlpatterns = patterns('', ..... url('^dict/persons/(?P<person_id>\d+)/$', persondetail, name = 'persondetail'), ..... )
SiteTree 项目配置:
Title: 'Person detail' URL: 'app:persondetail person.id'
URL 作为模式(选中)
结果很糟糕 - SiteTree 菜单无法正常工作 - 它不会呈现菜单元素和面包屑。在其他页面上它有效。
我还尝试编写 URl 模式,例如:
- 'app:persondetail person.id'
- 'app:persondetail person_id'
- 'app:persondetail Person.id'
- 'app:persondetail Person_id'
- 'app:persondetail {{person.id}}'
- 'app:persondetail {{Person.id}}'
- 'app:persondetail #person.id'
- 'app:persondetail #Person.id'
- with quotes and without
但它仍然不起作用。
我的项目结构是:
- project
|___main_app
| |___urls.py:
| from django.conf.urls import patterns, include, url
| from django.contrib import admin
| admin.autodiscover()
|
| urlpatterns = patterns('',
| url(r'^', include('app.urls', namespace="app")),
| url(r'^admin/', include(admin.site.urls)),
| )
|
|___app
|___urls.py:
| from django.conf.urls import patterns, include, url
| from jdevtool.views import *
|
| urlpatterns = patterns('',
| .....
| url('^dict/persons/(?P<person_id>\d+)/$', persondetail, name = 'persondetail'),
| .....
|
| )
|
|___views.py:
.....
def persondetail(request, person_id):
pers = get_object_or_404(Person, pk=person_id)
return render(request, 'app/persDetail.html', {'pers': pers})
.....