[Django]-Get the path to Django itself

5đź‘Ť

âś…

So long as Django has already been imported in the Python process (which it has, if your code is, for example, in a view function), importing it again won’t do “anything”* — so go nuts, use import django; django.__file__.

Now, if Django hasn’t been imported by the current Python process (eg, you’re calling os.system("myscript.py") and myscript.py needs to determine Django’s path), then import django will be a bit wasteful. But spawning a new process on each request is also fairly wasteful… So if efficiency is important, it might be better import myscript anyway.

*: actually it will set a value in a dictionary… But that’s “nothing”.

👤David Wolever

Leave a comment