since some week I have started to work with django. Now i would like to use django-sitetree to create a navigation bar through my models. But i have problems with the definition of the sitetree. For example, i want to create following menu structure:
maintree
|
|-- Media
| |-- Movies
| | |-- Life of Pi
| | |-- Django unchained
Okay. So i have create following simple model:
class Movies(models.Model):
title = models.CharField(max_length=50)
To test sitetree i added the data set like "Life of Pi" through the django admin site.
However, now i tried to work with the gettings started documentation from https://django-sitetree.readthedocs.org/en/v0.9/quickstart.html with the modification to my models.
Inside the Django admin site i have execute following steps:
- Home › Sitetree --> Add site tree
- Title = maintree
- Alias = maintree
- Home › Sitetree › Site Trees › maintreeHome › Sitetree › Site Trees › maintree --> Add site tree item
- Parent = no parent (------)
- Title = Media
- URL = /exam
- Home › Sitetree › Site Trees › maintreeHome › Sitetree › Site Trees › maintree --> Add site tree item
- Parent = Media
- Title = Movies # {{movie.id}}
- URL = movie-detailed movie.title
- 'Additional settings': check 'URL as Pattern' has been set too
Okay the next step was to write an base.html that looks like this:
{% load sitetree %}
<!DOCTYPE html>
<html>
<head><title>My test template</title></head>
<body>
<b>Sitetree menu</b>
{% sitetree_tree from "maintree" %}
<b>Breadcrumbs</b>
{% sitetree_breadcrumbs from "maintree" %}
</body>
</html>
My URLS look like this:
from django.conf.urls import patterns, url
from exam.views import IndexView, DetailedMovie
urlpatterns = patterns('',
url(r'^$', IndexView.as_view()),
url(r'^(?P<movie_title>\S+)/$', DetailedMovie.as_view(), name='movie-detailed'),
)
And the view like this:
class DetailedMovie(TemplateView):
template_name = "index.html"
def get(self, request, *args, **kwargs):
print 'DetailedMovie ---------------------'
print args
print kwargs
return render(request, 'index.html')
The Problem
Finally my problem is that the result is different then i have expected. I see only Media and Movies # but not the Movie Data (Life of pie and Django unchained). By checking what the view got as parameter kwargs results: {'movie_title': u'movie.title'}.
So now i'm not sure what is wrong. I hope someone could help me to solve this problem or suggest me another app or method to get such a navigation tree with breadcrumbs.
Thanks
You forget to pass
movie
variable into your template: i.e. if you doTitle = Movies # {{movie.id}}
your view should return something likerender(request, 'index.html', {'movie': my_movie})
, wheremy_movie
is your Movie object. That said,get
should probably acceptmovie_title
arg, as it is put in youurlpatterns
, so that you can deduce an appropriate Movie object from it.