9
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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)

##参考
https://stackoverflow.com/questions/7867797/how-do-i-reference-a-django-settings-variable-in-my-models-py

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?