-
-
Save mhulse/1254423 to your computer and use it in GitHub Desktop.
"{{ 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, | |
} | |
""" |
You could use a plain (not class-based) view function and the render() or render_to_response() shortcut. But that would require only marginally less code.
Thanks for the help eppsilon! I really appreciate it. :)
I definitely don't mind the code above... Basically I just wanted to make sure that I was properly using the "TemplateView", class-based generic view, for something as simple as passing URL param to a template.
I feel pretty comfortable with the old functional view stuff, but for some reason the new class-based views have been giving me trouble. :D
Thanks so much for you help and taking the time to give a helpful answer.
Cheers,
Micky
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".
Is there a faster way of doing the above?
Discussion found here.