pythonをwebで動かしてみたく、ローカルホストにあげてみたのですが、上手くいきません。
最初の画面は上手に映るのですが、そのあと、pythonで書いたコードのページに飛ぼうとすると404エラーになってしまいます。
urlがlocalhost8000でコードを書いてるはずなのにlocalhost63341で開かれています。こらが原因だと思うのですが、コードには8000で書いています。何がいけないのでしょうか。
html
1<html> 2<head> 3<meta http-equiv="content-type" content="text/html;charset=utf-8"> </head> 4<body> 5 <center><br><br> 6 <form action="/cgi-bin/janken.py" method="POST"><h1><font color="#FF7F50">じゃーんけーん</font></h1><br /><br /> 7 <font size="5"><input type="radio" name="janken" value=1>グー<br /> 8 <input type="radio" name="janken" value=2>チョキ<br /> 9 <input type="radio" name="janken" value=3>パー<br /><br /></font> 10 <input type="submit" name="submit" /> 11 </form> 12 </center> 13</body> 14</html> 15 16
python
1# -*- coding: utf-8 -*- 2# !/usr/bin/env python 3 4import cgi 5import random 6 7form = cgi.FieldStorage() 8 9dic = {"1": "グー", "2": "チョキ", "3": "パー"} 10 11user = form.getfirst('janken') 12user_choice = dic[user] 13 14choice_list = ["1", "'2", "3"] 15pc = dic[random.choice(choice_list)] 16 17draw = '<font color="#32CD32">DRAW</font>' 18win = '<font color="#FF7F50">You Win!!</font>' 19lose = '<font color="#0000FF">You lose!!</font>' 20 21if user_choice == pc: 22 judge = draw 23else: 24 if user_choice == "グー": 25 if pc == "チョキ": 26 judge = win 27 else: 28 judge = lose 29 30 elif user_choice == "チョキ": 31 if pc == "パー": 32 judge = win 33 else: 34 judge = lose 35 36 else: 37 if pc == u"グー": 38 judge = win 39 else: 40 judge = lose 41 42 43html_body = """ 44<html><body><center><br><br><br> 45あなたが選んだのは %s<br><br> 46コンピュータが選んだのは%s<br><br> 47<font size="5"> 結果は %s </font><br><br> 48<a Href ="http://127.0.0.1:8000/janken.html">戻る</a> 49</center></body></html>""" % (user_choice, pc, judge) 50 51print("Content-type: text/html\n") 52print(html_body)

回答1件
あなたの回答
tips
プレビュー