LoginSignup
3
2

More than 5 years have passed since last update.

Python による簡易 Webサーバ 作成に関するメモ

Posted at

Local

html ファイルを保存したディレクトリで、

#python2

$ python -m SimpleHTTPServer

#python3

$ python3 -m http.server

ブラウザで http://localhost:8000 を表示。

CGIHTTPServer

~/renshu$ mkdir cgi-bin
~/renshu$ cd cgi-bin
~/renshu/cgi-bin$ nano cgi-hello.py
~/renshu/cgi-bin$ chmod 755 cgi-hello.py
~/renshu/cgi-bin$ cd ..
~/renshu$ python3 -m http.server --cgi

cgi-hello.py

#!/usr/bin/env python3
# -*- coding:utf-8 -*-

print('Content-type: text/html; charset=UTF-8\r\n')
print('Hello, World!')

http://localhost:8000/cgi-bin/cgi-hello.py

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2