python重定向的三種方式

2021-10-14 11:45:42 字數 737 閱讀 6221

使用django中的redirect方法,也是最常用的方法

from django.shortcuts import redirect
return redirect('')
重定向預設都是302(臨時重定向),加上permanent就可以設定為301(永久重定向)

return redirect("",permanent =true)
使用httpresponseredirect來進行重定向

from django.http import httpresponseredirect
return httpresponseredirect("")
建立乙個httpresponse響應物件,然後修改location來進行重定向

1.response = httpresponse()    #建立響應物件
2.response.status_code = 302   #將狀態碼設定為302臨時重定向
3.response["location"] = ""   #修改響應頭的location來進行跳轉

PHP URL重定向的三種方法

1.使用header 函式 php的http相關函式種提供了乙個 header 函式,首先要清楚,header 函式必須放在php程式的開頭部分,而且之前不能有另外的 header 函式或者 setcookie 被呼叫,如果是帶有網頁輸出,本語句必須放在標記之前。使用如下語句 header loca...

PHP重定向三種方法詳解

方法一 header location url 方法二 方法三 php的http相關函式種提供了乙個 header 函式,首先要清楚,header 函式必須放在php程式的開頭部分,而且之前不能有另外的 header 函式或者 setcookie 被呼叫,如果是帶有網頁輸出,本語句必須放在標記之前。...

Spring重定向的兩種方式

spring mvc重定向 兩種實現方式 1 response的重定向 response.setcontenttype text html charset utf 8 string url searchsmallmajorbyname.action?parentid parentid searchs...