views:

62

answers:

4

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?

+5  A: 
from django.conf import settings

should do it!

lazerscience
A: 

Use one of these methods.

Ignacio Vazquez-Abrams
A: 

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.

emperorcezar
A: 

you can use

from mysite.settings import VARIABLE_NAME
eos87