お世話になります。
Tatsuyaと申します。
只今"独習Python入門"という本を読みながら
プログラミングの勉強をしているのですが、
cgiを使用したプログラムを作成中に画面が真っ白になり。
思うように動作しない為ご相談させていただきました。。
コードの内容としては、pythonにてWebサーバーを作り、
そこのhtmlの入力フォームに入力されたものをPythonで反映するというものです。
環境はVirtualbox上のCentOS7をGnomeにて使用。
言語はPython3。
これまで、シバンをusr/local/Anaconda3/bin/python3に変更したり、
パーミッションを777に変えてみたり、改行コードをLR、LRCFに変えてみたりと試しましたが結果は変わらずでした。
html
1<!DOCTYPE html> 2<html lang="ja"> 3<head> 4 <meta charset="utf-8"> 5 <title>はじめてのWebアプリケーション!</title> 6 <style type="text/css"> 7 h1 { 8 background:#eee; 9 border:1px soloid #ccc; 10 border-left:7px solid #e3297d; 11 padding:15px 20px; 12 } 13 </style> 14</head> 15<body> 16 <h1>あなたのお名前はなんというのですか?</h1> 17 <form action="/cgi-bin/name.py" method="get"> 18 <p>お名前:<input type="text" name="name"/></p> 19 <button type="submit">送信</button> 20 </form> 21</body> 22</html>
Python
1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3 4import cgi 5 6 7html_body = """ 8<html> 9<body> 10<p>あなたのお名前は<span style="font-size:48px"> %s </span>さんです!</p> 11</body></html> 12""" 13 14form = cgi.FieldStorage() 15 16print("Content-Type: text/html") 17print(html_body % form["name"].value)
Python
1import http.server 2http.server.test(HandlerClass=http.server.CGIHTTPRequestHandler)
お手数をおかけいたしますが、
ご教示いただけますと幸いです。
よろしくお願いいたします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/03/07 10:01
2017/03/07 10:07
2017/03/07 10:39
2017/03/07 11:40