开发者

Make a redirect page that takes the user to one of the 5 forms (has to be random)

开发者 https://www.devze.com 2023-04-06 01:22 出处:网络
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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消