17、Django重定向返回上一页

from django.http import HttpResponseRedirect

# 函数中
def someview(request):
   ...
   return HttpResponseRedirect(request.META.get('HTTP_REFERER'))



# 类视图中
from django.http import HttpResponseRedirect
    ...
    return HttpResponseRedirect(self.request.META.get('HTTP_REFERER'))
from django.shortcuts import redirect

redirect(request.path_info) # No query parameters

redirect(request.build_absolute_uri()) # Keeps query parameters

redirect(request.get_full_path()) # Keeps query parameters

Last updated