Okay, don't be so frustrated. Let's look at this step by step:
Python path syntax:
In Python, when you split your code base across modules, you qualify the name of the import with the name of the module. Let's say your project is structured like this:
my_project |__utils | |____init__.py | |__file_utils.py |__my_module |____init__.py |__main.py
In your
main.py
if you want to access methods you have defined infile_utils.py
you add an import statement in yourmain.py
like this:import utils.file_utils.read_file
assuming
read_file
is the method you want to import intomain.py
. This way of importing modules where you have a.
separating every module is referred as python path syntax.PYTHONPATH:
In the above example, the import statement would work only if the Python interpreter knows where to look for the first module namely the
utils
. Only when it findsutils
can it findfile_utils
andread_file
. You specify the list of all the paths you want the interpreter to look into in the environment variablePYTHONPATH
. So in order to have an import statement like above in your code, you have to make sure that the full path to your projectmy_project
is inPYTHONPATH
. Assumingmy_project
is inC:\AMAZEBALLS_CODE\my_project
you should haveC:\AMAZEBALLS_CODE
in yourPYTHONPATH
DJANGO_SETTINGS_MODULE:
Now let's suppose your
my_project
is actually a Django application. A Django application needs a settings file where you specify a whole bunch of things. In order to instruct Django which settings file to look into you specify it inDJANGO_SETTINGS_MODULE
. Assuming this is your project structure:my_project |__utils/ | |____init__.py | |__file_utils.py |__my_module/ | |____init__.py | |__main.py |__site_settings/ |__dev_settings.py |__production_settings.py
myroject.site_settings
is the module Django has to look into for the settings file. Andmyroject.site_settings.dev_settings
is the value you need to be setting to theDJANGO_SETTINGS_MODULE
in the above case. When documentation sayscms.settings
ormysite.settings
they meancms
ormysite
is the name of your project andsettings.py
is the name of your settings file.
Now let's look at your question:
Can you permanently set it in the environment variables of Windows? Sure.
Is it the right way? No.
Because if you want to create another application tomorrow in another location, you will have to edit this in the environment variables section of Windows. Also, it is a practice to use a different settings file for development environment and another one for production. So setting it at one place with one value makes it inflexible. But if you are aware of all of the above and sure you are gonna be using just the one settings file set DJANGO_SETTINGS_MODULE
to myproject.site_settings.dev_settings
in the env variables section.
Hope this helps!
EDIT:
Looks like you are putting your pysec-master
project in C:\Python27
. Do not put your projects in the python installation. Create a settings.py
file in your project and set DJANGO_SETTINGS_MODULE
to pysec-master.settings