Friday, September 30, 2011

Re: [Django 1.3] django.views.generic.TemplateView example


On Saturday, October 1, 2011, Micky Hulse <rgmicky@gmail.com> wrote:
> Code:
>
> <https://gist.github.com/1254423>
>
> When using the new class-based generic views, is there a faster way
> for me to pass URL params to the template?

There's no need to subclass TemplateView and provide your own implementation of get_context_data() - the default TemplateView implementation does exactly (and I mean character-for-character exactly) what you've defined. So, you just need to deploy a default TemplateView in your urls.py:

('^foo/(?P<id>\d+)/$', TemplateView.as_view(template_name='my_template.html'))

Your template should work exactly as-is.

I know the class-based views docs aren't as good as they could be - thats mostly my fault. I also know that "read the source" isn't a real documentation answer. However, the CBV code is quite well documented internally, and isn't all that complex at the end of the day - if you've got questions about how to do something obscure with CBVs, a quick peruse of the source is well worth your time.

Yours,
Russ Magee %-)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment