0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

SJISで書かれたWebフロントエンドページを自PCのブラウザで表示する方法

Posted at

SJISで書かれたWebフロントエンドページを自PCのブラウザで表示する方法

sjis_server.py
# -*- coding: shift_jis -*-

from http.server import HTTPServer, SimpleHTTPRequestHandler
import re

class ShiftJISHandler(SimpleHTTPRequestHandler):
    def end_headers(self):
        if self.path.endswith(".html"):
            self.send_header("Content-Type", "text/html; charset=Shift_JIS")
        super().end_headers()

if __name__ == "__main__":
    port = 8000
    print(f"📡 サーバーを起動中: http://localhost:{port}")
    httpd = HTTPServer(("localhost", port), ShiftJISHandler)
    try:
        httpd.serve_forever()
    except KeyboardInterrupt:
        print("\n🛑 サーバーを停止しました")

をUTF-8で保存。

以下のコマンドでサーバを起動:

python sjis_server.py

ブラウザで http://localhost:8000/ にアクセス。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?