2017-08-30 105 views
0

你好,我正在學習Python和一個新手,我不能設置一個邏輯爲,如果後數據不符合,後網頁會被重定向到原始頁。 經過很長時間的搜索,我發現這個how to redirect one page to another,但仍然有關於重定向頁面的困惑。 這裏是我的html代碼:如何將頁面重定向到另一個頁面在Python 3 CGI最近

<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 

在這裏,在那裏把標題代碼和所有的工作人員在形式和如何從重定向到原始頁張貼頁面,如何設置所有的東西?請幫我理解流程的流程?

和一個請求請不要downvote,我是新的python。

+1

這很難不給你當downvote」已經給了這些有限的細節。你爲什麼只顯示html?你提到的所有東西都發生在Python代碼中。 –

+0

肯定等一下,我給你PY代碼 –

+1

WRT到你的「如何在一個頁面重定向到另一個」鏈接:它已經很少跟你的問題(你鏈接到一個問題是關於HTTP客戶端代碼,不是HTTP服務器代碼,這是你在做什麼)。另外,如果您希望進行任何網絡編程,您需要了解HTTP協議(請求和響應部分)。 –

回答

0
#! /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) 

我做了很多 - [R & d,最終找到這一點,將是完美的解決方案,因此far.If你覺得不合適,請糾正it.Thank你

相關問題