So I am learning CGI programming with Python and i need to create some forms that ask input from the users and use the input to display开发者_Go百科 some results. I will have to create five different forms (hence different results) and I want to have a "play again" button on the result page so that when users click on it they can be directed to one of the five forms. I read a lot on redirecting but in my case, I can't just put an url because I want a random page generated. How can I do this?
Thank you!!
You can use the python module random
.
import random
urls = [
'form1.html',
'form2.html',
'form3.html',
'form4.html',
'form5.html',
]
redirect_to = random.choice(urls)
# then do your redirection stuff
http://docs.python.org/library/random.html
精彩评论