return redirect(url_for('index', var=var))
return render_template('index.html', var=var)
这两条线基本上是一样的东西吗?render_template和重定向之间的区别?
这两个函数有什么区别?
return redirect(url_for('index', var=var))
return render_template('index.html', var=var)
这两条线基本上是一样的东西吗?render_template和重定向之间的区别?
这两个函数有什么区别?
redirect
向浏览器返回一个302标题,其Location
标题作为index
函数的URL。 render_template
返回200,并将index.html模板作为该URL的内容返回。
在一个简单得多的笔记中,考虑一下 - 如果您的终端都没有呈现模板,并且您的所有重定向都是在应用内的端点网址上,那么将不会呈现任何内容!
这就像指向一个地方不会显示自己的方式。