回答編集履歴

1

Python 3でcgiを動かすことが出来た事を追記しました

2016/09/08 03:05

投稿

taro_nii_chan
taro_nii_chan

スコア207

test CHANGED
@@ -47,3 +47,89 @@
47
47
  何故2系が動いているのかはもう少し調べ、
48
48
 
49
49
  分からなかったら別の質問としてお知恵を拝借することにします。
50
+
51
+
52
+
53
+ ---
54
+
55
+ 追記
56
+
57
+ [https://www.python.org/downloads/](https://www.python.org/downloads/)
58
+
59
+ から改めてPython 3をインストールし直し、
60
+
61
+ `index.py`の1行目を
62
+
63
+ ```Python
64
+
65
+ #!/usr/local/bin/python3
66
+
67
+ ```
68
+
69
+ とすることで
70
+
71
+ ```
72
+
73
+ Hello World!
74
+
75
+ ```
76
+
77
+ と表示されるようになりました。
78
+
79
+
80
+
81
+ index.py
82
+
83
+ ```Python
84
+
85
+ #!/usr/local/bin/python3
86
+
87
+ # -*- coding: UTF-8 -*-
88
+
89
+
90
+
91
+ # enable debugging
92
+
93
+ import cgitb
94
+
95
+ cgitb.enable()
96
+
97
+ import sys
98
+
99
+
100
+
101
+ print("Content-Type: text/plain;charset=utf-8")
102
+
103
+ print()
104
+
105
+
106
+
107
+ print("Hello, world!")
108
+
109
+ print(sys.version)
110
+
111
+ ```
112
+
113
+
114
+
115
+ ```
116
+
117
+ <TITLE>CGI script output</TITLE>
118
+
119
+ <H1>This is my first CGI script</H1>
120
+
121
+ Hello, world!
122
+
123
+ 3.5.2 (v3.5.2:4def2a2901a5, Jun 26 2016, 10:47:25)
124
+
125
+ [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
126
+
127
+ ```
128
+
129
+ と確かにPython 3が動いているのを確認済みです。
130
+
131
+
132
+
133
+ ただ、htmlタグがそのまま文字列として表示されていることに関してはまだ不明なので、
134
+
135
+ 調べて分からなかったらまたお知恵を拝借します。