Whenever I put in a (random) print
statement in somewhere like settings.py
or any random .py
file in django, it gets printed twice. Why?
Try this:
after setting the value on TEMPLATE_DIRS
(in settings.py
), just add a print statement after it:
print TEMPLATE_DIRS
and you will get your templates directory printed out twice. Or if you're feeling old-fashioned, just add print "Hello World
right after declaring TEMPLATE_DIRS
, and it will print it twice.
Command to run : python manage.py runserver
It's not running it twice, it's forking to 2 processes and each one of those is running it once.
Answered by: why is init module in django project loaded twice
It should be loaded only once... per process. I'm guessing that manage.py forks, and that two separate processes are launched.
and an article.
To verify this if you add this to your settings.py
import os
print(os.getpid())
It will print out 2 different process id numbers showing that it's spawned 2 processes.
You can read more about forking on wikipedia.
This also seems a duplicate of:
django - settings.py seems to load multiple times?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With