如何满足direct_to_template的导入?

发布于 2021-01-29 16:11:47

我从最初的Pinax 0.7项目中收到错误页面:

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

它停在的行urls.py:3是:

from django.views.generic.simple import direct_to_template

如何更改导入或使用该导入的区域:

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

看起来我可以在主页上创建一个执行render_to_response()的视图,但是我想知道我应该如何解决它,如果没有人告诉我一种更好的方法,请改用该视图。

关注者
0
被浏览
52
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

    direct_to_template已不推荐使用。在django 1.5中,尝试在中使用基于类的视图urls.py

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

    有一个关于迁移到1.4版本的一些信息(当它被废弃)这里



知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看