返回django中的重定向1.5抛出导入异常

ted*_*toy 0 django

我有简单的代码,基本上看起来像这样:

from django.shortcuts import redirect
def my_view(request):
    ... does stuff
    return redirect('/some_other_url/')
Run Code Online (Sandbox Code Playgroud)

抛出的异常是"无法导入django.views.generic.simple.redirect_to.父模块django.views.generic.simple不存在." 当我注释掉"返回重定向"代码(并替换为返回HttpResponse(""))时,我不再收到错误.

堆栈跟踪:不再可用,因为它是在SO http://dpaste.com/1007500/ 之外发布的

我刚刚从django 1.3.1升级到django 1.5.检查1.5的文档,看起来我仍然可以使用"redirect()".我从几个谷歌搜索中找不到任何答案,所以希望它不是我的盲目疏忽.

sta*_*alk 11

看起来问题不在django.shortcuts.redirect,但在视图中,您被重定向到的进程网址.根据你的追溯,查看,该进程url 127.0.0.1:8000/post_station/使用某处django.views.generic.simple.redirect_to.在django 1.5你可能不应该这样做.使用django.views.generic.RedirectViewinsead.

你可以在这里找到答案"Django中没有名为simple的模块"错误

  • 谢谢,在我的urls.py文件中使用simple.redirect_to确实是一个问题. (2认同)