###前提・実現したいこと
簡単なチャットアプリを作ってブラウザ上に表示しようとしているのですが、コマンドプロントから簡易サーバを立て、localhostにアクセスしてもブラウザにhtmlが表示されません。エラーにはなっていないのでどこが間違っているのかわからない状態です。
プログラミング初心者ですが、解決のほどよろしくお願いします。
###発生している問題・エラーメッセージ
ブラウザに表示されない。エラーは出ていない
###該当のソースコード
#!/usr/bin/env python3 import cgi import cgitb import os.path import html cgitb.enable() FILE_LOG = "chat-log.txt" #HTMLの描画 def print_html(body): print("Content-Type: text/html; charset = utf-8") print("") #htmlを出力 print(""" <html> <head> <meta charset = "utf-8"> <title>チャット</title> </head> <body> <h1>チャット</h1> <div> <form> 名前:<input type = "text" name = "name" size = "8"> 本文:<input type = "text" name = "body" size = "20"> <input type = "submit" value = "発言"> <input type = "hidden" name = "mode" value = "write"> </form> </div> <hr> {0} </body> </html> """.format(body)) def mode_read(form): log = "" if os.path.exists(FILE_LOG): with open(FILE_LOG,"r",encoding='utf-8') as f: log = f.read() print_html(log) def jump(url): print("Status: 301 Moved Permanently") print("Location: " + url) print("") print('<html><head>') print('<meta http-equiv = "refresh" content = "0;'+ url +'">') print('</head><body>') print('<a href = "'+ url +'">jump</a></body></html>') def mode_write(form): name = form.getvalue("name","no name") body = form.getvalue("body", "") name = html.escape(name) body = html.escape(body) with open(FILE_LOG, "a+", encoding='utf-8') as f: f.write("<p>{0}: {1}</p><hr>\n".format(name,body)) jump('prac.py') def main(): form = cgi.FieldStorage() mode = form.getvalue("mode", "read") if mode == "read": mode_read(form) elif mode == "write": mode_write(form) else: mode_read(form) if __name__ == "__main__": main()
###試したこと
プログラム上、バグがないのは確認済みです。
pcは64bitでpythonは32bitで実行していたのでそれが怪しいのかなと思いましたが、正解が分かりません。さらにこのほかにも簡単なHTMLファイルを作って実行しましたが、その時は%1 は有効なWin32アプリケーションではありません」と表示されてしまいました。
###補足情報(言語/FW/ツール等のバージョンなど)
より詳細な情報
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。