How can I satisfy an import of direct_to_template?
Asked Answered
S

2

23

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

ImportError at /
No module named simple
Request Method: GET
Request URL:    http://stornge.com:8000/
Django Version: 1.5
Exception Type: ImportError
Exception Value:    
No module named simple
Exception Location: /home/jonathan/clay/../clay/urls.py in <module>, line 3
Python Executable:  /home/jonathan/virtual_environment/bin/python
Python Version: 2.7.3
Python Path:    
['/home/jonathan/clay/apps',
 '/home/jonathan/virtual_environment/local/lib/python2.7/site-packages/pinax/apps',
 '/home/jonathan/clay',
 '/home/jonathan/virtual_environment/local/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg',
 '/home/jonathan/virtual_environment/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg',
 '/home/jonathan/virtual_environment/lib/python2.7',
 '/home/jonathan/virtual_environment/lib/python2.7/plat-linux2',
 '/home/jonathan/virtual_environment/lib/python2.7/lib-tk',
 '/home/jonathan/virtual_environment/lib/python2.7/lib-old',
 '/home/jonathan/virtual_environment/lib/python2.7/lib-dynload',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-linux2',
 '/usr/lib/python2.7/lib-tk',
 '/home/jonathan/virtual_environment/local/lib/python2.7/site-packages',
 '/home/jonathan/virtual_environment/local/lib/python2.7/site-packages/PIL']
Server time:    Mon, 25 Mar 2013 13:16:33 -0400

The line it is balking on, urls.py:3, 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.

Salleysalli answered 25/3, 2013 at 17:26 Comment(1)
Breadcrumb remark: I made this post as part of a concerted effort to get a Pinax 0.7.3 social project to work with a more recent version of Pinax (for reasons beyond me, the social project in Pinax 1.0.0 is a bare stub, complete with lorem ipsum in the final page). It took me a lot of digging to get to Pinax 0.7.3 (there are innumerable places advertising a free Pinax 0.7.3 download, but I tried dozens and they all pointed to a pinaxproject.com (now) 404. Having found Pinax 0.7.3 and wanting to save other programmers the headache, I have made it available at JonathansCorner.com/pinaxSalleysalli
E
54

direct_to_template has been deprecated. In django 1.5 try using a class based view TemplateView in urls.py

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.

Eurhythmic answered 25/3, 2013 at 17:37 Comment(1)
Works in Django 1.9Unity
V
2

Besides the class-based view TemplateView, you can also use the render function like this:

from django.shortcuts import render

urlpatterns = patterns("",
    url(r'^$', lambda request: render(request, 'homepage.html'), name="home"),
)
Veradia answered 18/10, 2016 at 17:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.