如何在 Python 3 cgi 中将一个页面重定向到另一个页面

How to redirect a page to another page in Python 3 cgi

我最近在学习Python,初学者。我无法将逻辑设置为,如果 post 数据不合格,post 页面将被重定向到原始页面。

经过一些研究,我发现了这个 how to redirect one page to another,但仍然对重定向页面感到困惑。

这是我的 html 代码:

<form action="generate_timing_data.py" method="POST"> <p>Select an athlete from the list to work with: </p><input type="radio" name="which_athlete" value="Mikey McManus"> Mikey McManus<br /> <input type="radio" name="which_athlete" value="Julie Jones"> Julie Jones<br /> <input type="radio" name="which_athlete" value="James Lee"> James Lee<br /><input type="radio" name="which_athlete" value="Sarah Sweeney"> Sarah Sweeney<br /><p> </p><input type=submit value="Select"> </form> 这是我的 python 代码:

import cgi
import athletemodel
import yate
form_data = cgi.FieldStorage()
if form_data['which_athlete'].value != '':
   //calculation stuff
else :
   //redirect stuff

这里header code和form的所有staff放在哪里,如何从post页面重定向到origin page,这些东西怎么设置?请帮助我了解流程流程?

#! /usr/bin/python3
import cgi
form_data=cgi.FieldStorage()
print('Content-type:text/html\n\n')
if 'username' not in form_data or 'password' not in form_data:
   redirectURL = "http://localhost:8081/"
   print('<html>')
   print('  <head>')
   print('    <meta http-equiv="refresh" content="0;url='+str(redirectURL)+'" />') 
   print('  </head>')
   print('</html>')
else:
   print(form_data['username'].value)
   print(form_data['password'].value)

我做了很多研发,终于找到了这个,这将是完美的解决方案,所以 far.If 你觉得不合适,请纠正 it.Thank 你