简体   繁体   English

如何满足 direct_to_template 的导入?

[英]How can I satisfy an import of direct_to_template?

I am getting an error page from an originally Pinax 0.7 project:我从最初的 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

The line it is balking on, urls.py:3, is:它犹豫不决的行,urls.py:3,是:

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.看起来我可以创建一个在主页上执行 render_to_response() 的视图,但我想知道我应该如何解决它,如果没有人告诉我更好的方法,请回过头来。

direct_to_template has been deprecated. direct_to_template已被弃用。 In django 1.5 try using a class based view TemplateView in urls.py在 django 1.5 中尝试在urls.py使用基于类的视图TemplateView

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 .这里有一些关于迁移到 1.4 版(当它被弃用时)的信息

Besides the class-based view TemplateView , you can also use the render function like this:除了基于类的视图TemplateView ,您还可以像这样使用render函数:

from django.shortcuts import render

urlpatterns = patterns("",
    url(r'^$', lambda request: render(request, 'homepage.html'), name="home"),
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 动态direct_to_template - Dynamic direct_to_template 在django 1.9中相当于django.views.generic.simple import direct_to_template - What is the equivalent of from django.views.generic.simple import direct_to_template in django 1.9 如何在direct_to_template或urls.py中的简单视图中提供会话数据(不创建应用) - How to provide session data in direct_to_template or simple view in urls.py (without creating apps) 转换Django direct_to_template函数以使用基于类的视图 - Convert the Django direct_to_template function to use class based view Django - render()、render_to_response() 和 direct_to_template() 之间有什么区别? - Django - what is the difference between render(), render_to_response() and direct_to_template()? 如何使用相同的代码满足不同的字符串格式设置方案? - How can I satisfy different string formatting scenarios with the same code? 如何使 selenium + python 线满足 PEP 8 线长建议? - How can I make selenium + python lines satisfy PEP 8 line length recommendations? 如何制作将满足django注册的“激活”和“注册”调用的导入? - How can I make imports that will satisfy django-registration's 'activate' and 'register' calls? 为什么我可以导入mako而不是mako.Template? - Why can I import mako and not mako.Template? 我该如何导入该功能? - How can I import the function?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM