Skip to content

Instantly share code, notes, and snippets.

@mhulse
Created September 30, 2011 17:26
Show Gist options
  • Select an option

  • Save mhulse/1254423 to your computer and use it in GitHub Desktop.

Select an option

Save mhulse/1254423 to your computer and use it in GitHub Desktop.
[Django 1.3] django.views.generic.TemplateView example
"{{ params.id }}"
from django.conf.urls.defaults import *
from django.views import generic
# from <app_name> import views
urlpatterns = patterns('',
# (r'^(?P<id>[a-zA-Z0-9]{32})/$', views.Show.as_view()),
# Example: d0732c86f9b44a428fc30e935ef90fcf
(r'^(?P<id>[a-zA-Z0-9]{32})/$', generic.TemplateView.as_view(
template_name='<app_name>/feed.html',
)),
)
from django.views import generic
"""
class Show(generic.TemplateView):
template_name = 'wire/feed.html'
def get_context_data(self, **kwargs):
return {
'params': kwargs,
}
"""
@mhulse

mhulse commented Oct 5, 2011

Copy link
Copy Markdown
Author

I posted an update in my urls.py file; I suppose that is one way to skip a view and go directly to template.

Looking at TemplateView class in the Django source code, kwargs is already passed to the template as a variable labeled "params".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment