网页使用CGI Python重定向到主页面

编程入门 行业动态 更新时间:2024-10-21 17:26:02
本文介绍了网页使用CGI Python重定向到主页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 作为我的第一个网络应用,我开发了一个非常简单的调查。用户每次刷新页面时都会询问用户随机提问。然后,当用户按下提交按钮时,它会自动进入页面,这是一个cgi脚本,使用post来保存数据库的答案。负责处理数据,由于它没有任何输出,它是一个空白页面。现在,如果用户想回答另一个问题,他们必须按下浏览器中的后退并刷新页面,这样就会弹出一个新问题。我不希望这样。

我希望当用户按下提交时,答案会自动转到处理脚本,页面会自动刷新新问题或者至少在处理后重定向到主调查页面,并带有一个新问题。

解决方案

你想要实现这个: en.wikipedia/wiki/Post/Redirect/Get

比听起来简单得多。接收POST的CGI脚本只需输出以下内容:

状态:303查看其他位置:http ://lalala/themainpage

As my first web app I developed a very simple survey. Random questions are being asked from the user anytime the page refreshes. The answer is sent to a cgi script using post to save the answers to the database.

However, when the user presses the submit button it automatically goes to the page which is responsible for processing the data and since it doesn't have any output it is a blank page. Now if the user wants to answer another question they have to press the "back" in the browser and refresh the page so a new question pops up. I don't want this.

I want it in a way that when the users pressed submit, the answers go automatically to the processing script and the page refreshes itself with a new question or at least after processing it redirects to the main survey page with a new question.

解决方案

You want to implement this: en.wikipedia/wiki/Post/Redirect/Get

It's much simpler than it sounds. The CGI script that receives the POST must simply produce the following output:

Status: 303 See other Location: lalala/themainpage

更多推荐

网页使用CGI Python重定向到主页面

本文发布于:2023-10-12 17:00:05,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   网页   主页   Python   CGI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!