首页 > 其他分享 >【Django Admin】点击保存后,重定向跳转

【Django Admin】点击保存后,重定向跳转

时间:2022-09-23 17:33:58浏览次数:52  
标签:info 重定向 Admin request Django result 跳转 order

第一种方式:

    # 保存后 重定向跳转
    def change_view(self, request, object_id, form_url='', extra_context=None):
        result_template = super().change_view(request, object_id, form_url, extra_context)
        result_template['location'] = '/admin/order/order'
        return result_template

 

 

第二种方式:

# 使用跳转html页面来帮助实现重定向,这个方法适合多加自定义内容


1: 添加跳转对应的html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
</body>
</html>

<script>
    alert("添加成功")
    window.location.href='/admin/order/order/';
</script>



2: 创建跳转接口函数
from django.shortcuts import render
def permission_page(request):
    return render(request, "info.html")



3: 创建跳转接口
 path('info', info_href.permission_page,name='permission')



4:接口返回重定向函数
return HttpResponseRedirect("/order/info")



PS:请求重定向函数跳转到HTML页面,页面经过JS重定向到想要的路由

 

标签:info,重定向,Admin,request,Django,result,跳转,order
From: https://www.cnblogs.com/wanghong1994/p/16723503.html

相关文章