我最近正在学习 Python 并且是初学者。我无法将逻辑设置为,如果帖子数据不合格,帖子页面将被重定向到原始页面。
经过一些研究,我发现了如何将一个页面重定向到另一个页面,但仍然对重定向页面感到困惑。
这是我的 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代码和所有员工放在表单中的位置以及如何从帖子页面重定向到原始页面,如何设置所有内容?请帮助我了解流程如何?
#! /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)
我做了很多研发,终于找到了这个,到目前为止是完美的解决方案。如果你觉得不合适,请更正。谢谢
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句