LoginSignup
0
1

More than 3 years have passed since last update.

[Pythonでweb開発] html出力時の文字化け対策

Last updated at Posted at 2020-01-19

色々と試しましたが、この方法が最適です。web serverとしても、localで起動する場合も文字化けしません。

import io
import os
import sys

html_body = 'HTMLの形式です'

if type(sys.stdout) == io.TextIOWrapper:
    sys.stdout = io.TextIOWrapper(
        sys.stdout.buffer, 
        encoding='utf-8'
print ('Content-type: text/html; charset=UTF-8\r\n')
print (html_body)

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