JonathanHayward JonathanHayward - 1 year ago 58
Python Question

How can I satisfy an import of direct_to_template?

I am getting an error page from an originally Pinax 0.7 project:

ImportError at /
No module named simple
Request Method: GET
Request URL:
Django Version: 1.5
Exception Type: ImportError
Exception Value:
No module named simple
Exception Location: /home/jonathan/clay/../clay/ in <module>, line 3
Python Executable: /home/jonathan/virtual_environment/bin/python
Python Version: 2.7.3
Python Path:
Server time: Mon, 25 Mar 2013 13:16:33 -0400

The line it is balking on,, is:

from django.views.generic.simple import direct_to_template

How can I change either the import or the area where it's used:

urlpatterns = patterns('',
url(r'^$', direct_to_template, {
"template": "homepage.html",
}, name="home"),

It looks like I can create a view that does a render_to_response() on the homepage, but I'd like to know how I should be solving it, and fall back on that if no one tells me a better way.

Answer Source

direct_to_template has been deprecated. In django 1.5 try using a Class based view in

from django.views.generic import TemplateView

urlpatterns = patterns('',
    url(r'^$', TemplateView.as_view(template_name='homepage.html'), name="home"),

There's some information on migrating to version 1.4 (when it was deprecated) here.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download