本文介绍了“No module named simple” Django中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $Django版本: pre>
我安装了最新的django版本。我正在使用
from django.views.generic.simple import redirect_to
我的urls.py中的pre>
哪里不对?是否已弃用?
解决方案使用,而不是
redirect_to
以下是基于类的视图使用的简单示例
来自django.conf.urls的模式导入模式,url,include
from django.views.generic import TemplateView
urlpatterns = patterns('',
r'^ about /',TemplateView.as_view(template_name =about.html)),
)
更新
如果有人想重定向到某个URL,请使用。
django.views.generic import redirectView
urlpatterns = patterns('',
pre>
(r'^ one / $',RedirectView.as_view(url ='/ another /')),
)
ImportError at / No module named simple Django Version: 1.5.dev20120710212642
I installed latest django version. I am using
from django.views.generic.simple import redirect_to
in my urls.py. What is wrong? Is it deprecated?
解决方案Use class-based views instead of
redirect_to
as these function-based generic views have been deprecated.Here is simple example of class-based views usage
from django.conf.urls import patterns, url, include from django.views.generic import TemplateView urlpatterns = patterns('', (r'^about/', TemplateView.as_view(template_name="about.html")), )
Update
If someone wants to redirect to a URL, Use RedirectView.
from django.views.generic import RedirectView urlpatterns = patterns('', (r'^one/$', RedirectView.as_view(url='/another/')), )
这篇关于“No module named simple” Django中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!