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

时间:2013-02-28 08:11:45

标签: django

我有简单的代码,基本上是这样的:

from django.shortcuts import redirect
def my_view(request):
    ... does stuff
    return redirect('/some_other_url/')

抛出的异常是“无法导入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()”。我几个谷歌的搜索都找不到任何答案,所以希望我不会盲目疏忽。

2 个答案:

答案 0 :(得分:11)

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

您可以在"No module named simple" error in Django

找到答案

答案 1 :(得分:1)

from django.shortcuts import redirect

def my_view(request):
    ... does stuff
    return redirect('/your_app/some_other_url/')