9
8

More than 5 years have passed since last update.

Django プロジェクトの settings.py に定義された変数を利用する

Posted at

DjangoProject/settings.py に定義した変数をmodels.pyやviews.pyで使いたいことがあります。
たとえば settings.py に PRIVATE_DIR が定義されているとします。

DjangoProject/settings.py
PRIVATE_DIR = 'c://tmp/'

この変数を、同じDjangoプロジェクトの中にある他のPythonファイルから利用するには、次のように書きます。

*.py
from django.conf import settings
PRIVATE_DIR = getattr(settings, "PRIVATE_DIR", None)

参考

9
8
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
9
8