当网页移动到新位置时,如何显示移动的网页并在Django中返回301永久重定向HTTP响应状态代码?
from django import http return http.HttpResponsePermanentRedirect('/yournewpage.html')
浏览器将获得301,并按/yournewpage.html
预期进行.另一个答案在技术上是正确的,因为python本身并不处理重定向,浏览器是.这就是幕后发生的事情:
Browser Python HTTP -------------------> GET /youroldpage.html HTTP/1.1 <------------------- HTTP/1.1 301 Moved Permanently Location: /yournewpage.html -------------------> GET /yournewpage.html HTTP/1.1