开发者

How do I include the Django settings file?

I have a .py file in a directory , which is inside the Django project folder.

开发者_运维技巧

I have email settings in my settings.py, but this .py file does not import that file.

How can I specify to Django that settings.py should be used , so that I can use EmailMessage class with the settings that are in my settings.py?


from django.conf import settings

should do it!


Depending on how you want to call your python script you can use one of a couple ways to accomplish what you want. The first is purely inside the python file.

from django.core.management import setup_environ
from mysite import settings

setup_environ(settings)

The second way is to setup your environment before calling the script

export DJANGO_SETTINGS_MODULE=yoursite.settings

Then from inside your script call

from django.conf import settings

That should set everything up for you.


you can use

from mysite.settings import VARIABLE_NAME
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜