Where is my Django installation?

PythonDjangoPathInstallation

Python Problem Overview


I use Django but I need to find the default templates and applications.

I don't know where it's installed.

How can I find that?

Python Solutions


Solution 1 - Python

in the CLI you can do this:

>>> import django
>>> django
<module 'django' from '/usr/local/lib/python2.6/dist-packages/django/__init__.pyc'>

Solution 2 - Python

$ python
>>> import django
>>> django.__file__
'/usr/local/lib/python2.7/site-packages/django/__init__.pyc'

Solution 3 - Python

The current top answer doesn't work, at least on linux.

From the Django tutorial:

> If you have difficulty finding where the Django source files are > located on your system, run the following command:

python -c "
import sys
sys.path = sys.path[1:]
import django
print(django.__path__)"

Solution 4 - Python

On Microsft-Windows OS: In the Lib/site-packages folder inside your python installation.

Solution 5 - Python

As the comments on @olafure's answer https://stackoverflow.com/a/12974642/4515198 rightly say, the sys.path assignment is not required.

The following will be enough:

python -c "import django; print(django.__path__)"

Here the -c option is used to tell python that a "program is being passed in as string" (source: command $ python --help on bash)

Solution 6 - Python

This approach I am describing works across operating systems...

You try this on your command line - python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"

This gives you the base directory. From there, type /django/ and here you find all the default templates, admin templates, etc.

Hope this helps...

Solution 7 - Python

import django
django.__file__

output will be given location of the django folder

'C:\\Users\\saigopi\\AppData\\Local\\Programs\\Python\\Python36\\lib\\site-packages\\django\\__init__.py'

Solution 8 - Python

Worth mentioning that if you are using a virtual env all the packages will be in your project's root venv folder under "lib" ...

Solution 9 - Python

Try this on an terminal.

$ python -v
import django # directory /home/user/.virtualenvs/myenv/local/lib/python2.7/site-packages/django
# some other imports.

Solution 10 - Python

If you are using virtualenv then it will be:
/home/user/path where you installed django/django_directory/lib/python2.7/site-packages/Django-1.8.1-py2.7.egg/django/contrib/admin/templates/admin/base_site.html
base-site.html is the default template.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPierre de LESPINAYView Question on Stackoverflow
Solution 1 - PythonUku LoskitView Answer on Stackoverflow
Solution 2 - PythonPierre de LESPINAYView Answer on Stackoverflow
Solution 3 - PythonolafureView Answer on Stackoverflow
Solution 4 - PythonExelianView Answer on Stackoverflow
Solution 5 - Pythonsatvik.tView Answer on Stackoverflow
Solution 6 - PythonSrikar AppalarajuView Answer on Stackoverflow
Solution 7 - Pythonsaigopi.meView Answer on Stackoverflow
Solution 8 - PythonhakiView Answer on Stackoverflow
Solution 9 - PythonAll Іѕ VаиітyView Answer on Stackoverflow
Solution 10 - PythonSumit NautiyalView Answer on Stackoverflow