【问题标题】:How can I satisfy an import of direct_to_template?如何满足 direct_to_template 的导入?
【发布时间】:2013-03-15 07:15:53
【问题描述】:

我从最初的 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() 的视图,但我想知道我应该如何解决它,如果没有人告诉我更好的方法,我就回过头来。

【问题讨论】:

  • 面包屑评论:我发表这篇文章是为了让 Pinax 0.7.3 社交项目与更新版本的 Pinax 一起工作(出于我以外的原因,Pinax 中的社交项目) 1.0.0 是一个裸存根,在最后一页中包含 lorem ipsum)。我花了很多时间才找到 Pinax 0.7.3(有无数地方宣传免费的 Pinax 0.7.3 下载,但我尝试了几十个,它们都指向 pinaxproject.com(现在)404。找到 Pinax 0.7 .3 并且为了让其他程序员免于头疼,我已将其发布在 JonathansCorner.com/pinax

标签: python django social-networking pinax


【解决方案1】:

direct_to_template 已被弃用。在 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"),
)

有一些关于迁移到版本 1.4 的信息(当它被弃用时)here

【讨论】:

  • 在 Django 1.9 中工作
【解决方案2】:

除了基于类的视图TemplateView,您还可以像这样使用render函数:

from django.shortcuts import render

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-02
    • 1970-01-01
    • 1970-01-01
    • 2017-10-06
    • 1970-01-01
    相关资源
    最近更新 更多