django redirect的几种方式
2016-05-05 17:57
120 查看
You can use the
By passing some object; that object’s
2 .By passing the name of a view and optionally some positional or keyword arguments; the URL will be reverse resolved using the
3.By passing a hardcoded URL to redirect to:
This also works with full URLs:
By default,
redirect()function in a number of ways.
By passing some object; that object’s
get_absolute_url()method will be called to figure out the redirect URL:
from django.shortcuts import redirect def my_view(request): ... object = MyModel.objects.get(...) return redirect(object)
2 .By passing the name of a view and optionally some positional or keyword arguments; the URL will be reverse resolved using the
reverse()method:
def my_view(request): ... return redirect('some-view-name', foo='bar')
3.By passing a hardcoded URL to redirect to:
def my_view(request): ... return redirect('/some/url/')
This also works with full URLs:
def my_view(request): ... return redirect('https://example.com/')
By default,
redirect()returns a temporary redirect. All of the above forms accept a
permanentargument; if set to
Truea permanent redirect will be returned:
def my_view(request): ... object = MyModel.objects.get(...) return redirect(object, permanent=True 以上摘自django文档。 大概来说就是有三种方式: 一。 return redirect(absolut_url) 或者相对路径 二。 return redirect(some views) 三。 见http://blog.csdn.net/orangleliu/article/details/38347863 在url conf中更改
另外见: http://www.yihaomen.com/article/python/327.htm
相关文章推荐
- 带交互的telnet小工具,golang版
- Google Code Jam 2016 R1B
- 网易视频云专家分享:Google Mesa论文笔记
- 查看django里所有的url
- go排序示例
- golang时间格式化
- Django笔记:5.激活模型
- “visible ”、“invisible”、“gone”
- Golang strings 包 用法详解
- go 协程使用陷阱
- 快速删除Mongo
- google一些搜索技巧
- Go语言的关键字
- Django session 详解-part II-session
- 安装Google浏览器一直报错 安装失败 0x80004002,非常有效
- Django笔记:4.创建模型
- sox 语音格式及播放软件goldwav
- 使用Google开源tesseract OCR用语言库报allow_blob_division解决方案
- Django笔记:3.开发服务器
- goldengate 目的端rep复制进程 遇到ora-00001 异常终止abend的血案