Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django - settings.py seems to load multiple times?

Tags:

django

pycharm

EDIT I miscounted - it is printed out twice, not four times.

I put this in my settings.py

print 'ola!'

and on startup "ola" is printed out twice! This seems like something is wrong with my pycharm django project ... any ideas why this would happen? It isn't in a loop or anything (that i'm aware of, anyway)

cheers!

YAY The user known only as "rohit", as per the comments, has determined that a solution can be found here: https://stackoverflow.com/a/2110584/1061426 ~ see the comment about disabling reloading.

CAUTION I don't have my Django code up and about now, so I don't know what the noload will do. Good luck, soldiers.

like image 381
bharal Avatar asked Jun 22 '12 03:06

bharal


People also ask

What does settings py do in Django?

settings.py is a core file in Django projects. It holds all the configuration values that your web app needs to work; database settings, logging configuration, where to find static files, API keys if you work with external APIs, and a bunch of other stuff.

Can I access constants in settings py from templates in Django?

"Django provides access to certain, frequently-used settings constants to the template such as settings. MEDIA_URL".

What need to set in settings py to tell Django which host to use when connecting to database?

If you want to connect through TCP sockets, set HOST to 'localhost' or '127.0.0.1' ('host' lines in pg_hba.conf ).

Where do I put settings py?

Create a settings.py file in your application's package (for example, if your application is named "myapp", put it in the filesystem directory named myapp ; the one with an __init__.py in it.


1 Answers

If you print out the thread ID within settings.py, you will see that settings.py is actually being loaded on two different threads.

See this stackoverflow response and this article for more info.

like image 171
jarmod Avatar answered Oct 17 '22 16:10

jarmod