... d into the WSGI environ, they are normalized by converting to uppercase, converting all dashes to underscores, and prepending HTTP_ . For instance ... , a header X-Auth-User would become HTTP_X_AUTH_USER in the WSGI environ (and thus also in Django's request.META dictionary). Unfortunately, this means that the WSGI environ cannot distinguish be ... ... dashes to underscores, and prepending HTTP_ . For instance, a header X-Auth-User would become HTTP_X_AUTH_USER in the WSGI environ (and thus also in Django's request.META dictionary). Unfortunately, this means that the WSGI environ cannot distinguish be ... ... dashes to underscores, and prepending HTTP_ . For instance, a header X-Auth-User would become HTTP_X_AUTH_USER in the WSGI environ (and thus also in Django's request.META dictionary). Unfortunately, this means that the WSGI environ cannot distinguish be ... ... モジュールにシークレットキーを直接書き込む代わりに、環境変数から読み込む方法を検討してください: import os SECRET_KEY = os . environ [ "SECRET_KEY" ] もしくはファイルから読み込みます: with open ( "/etc/secret_key.txt" ) as f : SECRET_KEY = f . read () . s ... trip () シークレットキーをローテーションする場合は、 SECRET_KEY_FALLBACKS : が使用できます: import os SECRET_KEY = os . environ [ "CURRENT_SECRET_KEY" ] SECRET_KEY_FALLBACKS = [ os . environ [ "OLD_SECRET_KEY" ], ] 古いシークレットキーが SECRET_KEY_F ... ... 定された URL 以下のすべての要求にサービスを提供するように Apache に指示します。 プロジェクトの Python 依存ファイルを virtual environment 内にインストールする場合は、 WSGIPythonHome を使ってパスを追加します。詳しくは mod_wsgi virtual environment guide を参 ... gi プロセスで実行されている場合は、それらのすべては、最初に実行されたものの設定を使用します。これを解消するには、次の os . environ . setdefault ( "DJANGO_SETTINGS_MODULE" , "{{ project_name }}.settings" ) という wsgi.py 内のコードを、次のように変更します ... 。 os . environ [ "DJANGO_SETTINGS_MODULE" ] = "{{ project_name }}.settings" もしくは、 mod_wsgi のデーモンモード を使用することで、各サイ ... ... o.core.mail.backends.smtp.EmailBackend" , "OPTIONS" : { "host" : "smtp.example.net" , "use_tls" : True , "username" : os . environ [ "EMAIL_ACCOUNT_ID" ], "password" : os . environ [ "EMAIL_API_KEY" ], }, }, "notifications" : { "BACKEND" : "example.thir ... d.party.EmailBackend" , "OPTIONS" : { "api_key" : os . environ [ "THIRD_PARTY_API_KEY" ], "region" : "eu" , }, }, "admin" : { "BACKEND" : "django.core.mail.backends.smtp.EmailBackend" , ... t" sends through an SMTP server at smtp.example.net with a TLS secured connection. It reads an account id and API key from environment variables and uses them as the SMTP authentication username and password. (Many SMTP services use some variation of th ... ... i ) の設定 実際のサーバ環境では、 WSGI アプリケーションにどの設定ファイルを使うのか教えてあげる必要があります。これには os.environ :: を使います。 import os os . environ [ "DJANGO_SETTINGS_MODULE" ] = "mysite.settings" さらなる情報や他のDjango WSGI アプ ... ... w recommended manage.py file should look like this: #!/usr/bin/env python import os , sys if __name__ == "__main__" : os . environ . setdefault ( "DJANGO_SETTINGS_MODULE" , "{{ project_name }}.settings" ) from django.core.management import execute_from_ ... o itself, so it's available to be adopted by an individual or group as a third-party project. django.core.management.setup_environ This function temporarily modified sys.path in order to make the parent "project" directory importable under the old flat ... his function was never documented or part of the public API, but it was widely recommended for use in setting up a "Django environment" for a user script. These uses should be replaced by setting the DJANGO_SETTINGS_MODULE environment variable or using ... ... nticated user as REMOTE_USER . In Django, this value is made available in request.META (as REMOTE_USER when supplied as an environment variable, as in WSGI, or HTTP_REMOTE_USER when supplied via an HTTP header, as in ASGI). Django can be configured to m ... der ASGI in all configurations, because there is no equivalent for a WSGI server's ability to place a trusted value in the environ. ASGI deployments must use a reverse proxy as described above when using this middleware. 認証メカニズムをより細かく制御し ... ... i を編集して、 check_password 関数をインポートすることで、Apacheの認証とサイトの認証メカニズムを紐づけます: import os os . environ [ "DJANGO_SETTINGS_MODULE" ] = "mysite.settings" from django.contrib.auth.handlers.modwsgi import check_password from djan ... 2026年10月08日