django-sitetree (0.9.4) won't render some menu and breadcrumbs elements

779 Views Asked by At

I have a problem with URL Patterns in SiteTree configuration. I have read the manual: https://django-sitetree.readthedocs.org/ru/latest/quickstart.html

So I'm trying to make my tree with named URLs:

  1. app/urls.py:

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

    Title: 'Person detail'
    URL: 'app:persondetail person.id'
    
  3. URL as Pattern (checked)

The result is bad - SiteTree menu does not work propetly - it doesn't render menu elements and breadscrumbs. On other pages it works.

Also I have tried to write URl pattern like:

    - '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

But it doesn't still work.

Structure of my project is:

- 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

There are 1 best solutions below

0
On BEST ANSWER

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

You're passing pers variable into your template, so you should tell exactly that to sitetree. Instead of app:persondetail person.id type — app:persondetail pers.id

The string put into sitetree URL field is essentially the same you'd use with url template tag, e.g.: {% url 'app:persondetail' pers.id %}.