python - 在 Django Python 中将一个 View 重定向到另一个 View

标签 python python-3.x django redirect django-views

如何从一个 View 重定向到另一个 View (下一个 View ):

class FooView(TemplateView):
  template_name 'foo.html'

  def post(self, *args, **kwargs):
    return redirect(BarView)
    # return redirect(BarView.as_view()) ???

class BarView(TemplateView):
  template_name 'bar.html'

最佳答案

在 urls.py 中为 URL 模式本身命名:

url('/bar/', BarView.as_view(), name='bar')

并将其传递给重定向:

return redirect('bar')

关于python - 在 Django Python 中将一个 View 重定向到另一个 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28071750/

相关文章:

python - 修改生成的查询以运行 LIKE 子句 - 红色查询生成器

python - cv2.VideoWriter 不会使用 fourcc h.264 写入文件(使用 logitech c920、python 2.7、windows 8)

python - 如何在单个 apache 服务上设置多个 django 版本?

python-3.x - 使用 pandas datareader 从 alpha vantage 提取股票数据时出错

python - 使用内置 sched 模块的非阻塞 scheduler.run() 方法?

python - 不支持在 include() 中指定命名空间而不提供 app_name

python - 检查模板 Django 中变量中字符串的某些部分

python - 无法更改 node-gyp 使用的默认 python 版本?

python - 使用 python 脚本实现 Windows 服务器和 Windows 桌面的差异

python - 无法在 Django 1.8 中设置评论功能