django中关于url跳转问题

  1. 我有两个页面 index 和 add; 127.0.0.1:8000/index/ 是主页面(index.html) 127.0.0.1:8000/add/ 是添加信息页面(add.html)
  2. 当在 index 页面中点击添加的时候跳到 add 页面进行添加信息操作;
    操作完保存之后自动跳回 index 页面,并且在 index 上显示刚刚添加的信息

    3.在 add(request) 函数中执行相关操作后,使用以下代码跳回 index.html的页面:

        return render(request, 'index.html', context={"user_info": ret[0], "in_info": ret[1]})
    

    4.这样虽然得到所要的页面,但是浏览器的 url 仍然是 127.0.0.1:8000/add/ 而不是 127.0.0.1:8000/index/

    5.若使用

    return redirect(reverse('index'))
    
  3. 而这种方法又不能把刚刚添加的信息显示在 127.0.0.1:8000/index/ 页面上,这个要怎么解决?

问题处理好了哈哈,用的还是第一种方法

return render(request, 'index.html', context={"user_info": ret[0], "in_info": ret[1]})

https://blog.csdn.net/qq_33867131/article/details/81949022