问题:我的Django安装在哪里?
我使用Django,但需要查找默认模板和应用程序。
我不知道它的安装位置。
我怎么能找到那个?
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?
回答 0
在CLI中,您可以执行以下操作:
>>> import django
>>> django
<module 'django' from '/usr/local/lib/python2.6/dist-packages/django/__init__.pyc'>
in the CLI you can do this:
>>> import django
>>> django
<module 'django' from '/usr/local/lib/python2.6/dist-packages/django/__init__.pyc'>
回答 1
$ python
>>> import django
>>> django.__file__
'/usr/local/lib/python2.7/site-packages/django/__init__.pyc'
$ python
>>> import django
>>> django.__file__
'/usr/local/lib/python2.7/site-packages/django/__init__.pyc'
回答 2
当前的最佳答案至少在Linux上不起作用。
从Django 教程中:
如果您很难找到Django源文件在系统上的位置,请运行以下命令:
python -c "
import sys
sys.path = sys.path[1:]
import django
print(django.__path__)"
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__)"
回答 3
在Microsft-Windows操作系统上:在python安装中的Lib / site-packages文件夹中。
On Microsft-Windows OS: In the Lib/site-packages folder inside your python installation.
回答 4
我正在描述的这种方法可跨操作系统使用…
您可以在命令行上尝试- python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"
这将为您提供基本目录。在此处输入,/django/
然后在其中找到所有默认模板,管理模板等。
希望这可以帮助…
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…
回答 5
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
)
回答 6
import django
django.__file__
输出将被赋予django文件夹的位置
'C:\\Users\\saigopi\\AppData\\Local\\Programs\\Python\\Python36\\lib\\site-packages\\django\\__init__.py'
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'
回答 7
值得一提的是,如果您使用的是虚拟环境,则所有软件包都将位于项目的“ lib”下的根venv文件夹中。
Worth mentioning that if you are using a virtual env all the packages will be in your project’s root venv folder under “lib” …
回答 8
在终端上尝试一下。
$ python -v
import django # directory /home/user/.virtualenvs/myenv/local/lib/python2.7/site-packages/django
# some other imports.
Try this on an terminal.
$ python -v
import django # directory /home/user/.virtualenvs/myenv/local/lib/python2.7/site-packages/django
# some other imports.
回答 9
如果您使用的是virtualenv,则它将是:
/ home / user / path,安装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是默认模板。
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.