django-sitetree(0.9.4)不会渲染一些菜单和面包屑元素

时间:2013-06-05 06:11:12

标签: python django django-sitetree

我在SiteTree配置中遇到了网址格式问题。我已阅读手册:https://django-sitetree.readthedocs.org/ru/latest/quickstart.html

所以我正在尝试使用命名网址创建我的树:

  1. 应用程序/ urls.py:

    urlpatterns = patterns('',
    .....
    url('^dict/persons/(?P<person_id>\d+)/$', persondetail, name = 'persondetail'),
    .....
    )
    
  2. SiteTree项目配置:

    Title: 'Person detail'
    URL: 'app:persondetail person.id'
    
  3. 作为模式的URL(已选中)

  4. 结果很糟糕 - SiteTree菜单无法正常工作 - 它不会渲染菜单元素和breadscrumbs。在其他页面上它可以工作。

    此外,我试图编写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})
              .....
    

1 个答案:

答案 0 :(得分:1)

render(request, 'app/persDetail.html', {'pers': pers})

您将 pers 变量传递到模板中,因此您应该确切地告诉 sitetree 。而不是app:persondetail person.id类型 - app:persondetail pers.id

放入 sitetree 网址字段的字符串与 url 模板标记使用的字符串基本相同,例如:{% url 'app:persondetail' pers.id %}