Get the path to Django itself

I have code that runs for every (almost) every administrator request, but does not have access to the request object.

I need to find a way to install Django. I could do:

import django
django_path = django.__file__

but it seems rather wasteful in the middle of the request.

Does import introduce memory modules at the beginning of the memory? I am sure there is no obvious trick here.

+3
source share
1 answer

As long as Django was already imported in the Python process (which it has, if your code is, for example, in the view function), importing it again will not do anything * so go nuts, use import django; django.__file__.

, Django Python (, os.system("myscript.py") myscript.py Django), import django . ... , , , import myscript.

*: ... "".

+5

Source: https://habr.com/ru/post/1745675/


All Articles