0

I am updating a Django project which used the direct_to_template as a function ie:

return direct_to_template(request, 'bprofile/init.html', targs)

As described a short way down this page

I have seen the SO question here and read the documentation on this page which decribe the migration of statements of the form

('^about/$', direct_to_template, {'template': 'about.html'})

to look like

('^about/$', TemplateView.as_view(template_name='about.html'))

Unfortunatelty I cannot seem to figure out how to change statements from the form that I have into a working new form.

How might one modify this code to work with the new Templateview form?

Community
  • 1
  • 1
Mr Purple
  • 2,325
  • 1
  • 18
  • 15

2 Answers2

2

You shouldn't be using the generic views for this, that's not what they are for. If you want to render a template, you should use the render shortcut: it takes exactly the same arguments.

return render(request, 'bprofile/init.html', targs)
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • Yep that did it. I just did a simple find and replace on "direct_to_template(" to "render(" and problem solved. Cheers. – Mr Purple May 28 '15 at 20:47
0

To use TemplateView you import TemplateView into your urls.py:

from django.views.generic.base import TemplateView

Then you just add the urlconf:

('^about/$', TemplateView.as_view(template_name='bprofile/init.html'))
jvc26
  • 6,363
  • 6
  • 46
  • 75