25

我正在尝试安装 django-extensions + graphviz + pygraph 但我不能。我已经完成了以下步骤(在 Ubuntu 下):

sudo apt-get install graphviz libgraphviz-dev graphviz-dev python-pygraphviz

在项目 virtualenv(运行 python 2.7.2+)中:

source <path to virtualenv>/bin/activate
pip install django django-extensions

如果我跑

which python

它在我的 virtualenv 中选择 python,所以我使用的 python 是正确的。在 virtualenv 的站点包中,我有 pygraphviz 和 django-extensions

python manage.py shell
import django_extensions
import pygraphviz 
RUNS OK

在我的 django 项目中,我在 INSTALLED_APPS 中添加了“django_extensions”

但是当我跑步时

python manage.py help

我看不到命令​​,它们不可用。

python manage.py graph_models -a -g -o model.png
Unknown command: 'graph_models'
Type 'manage.py help' for usage.

我怎样才能解决这个问题 ?谢谢!

4

2 回答 2

42

在 manage.py shell 中运行它:

from django.conf import settings; 'django_extensions' in settings.INSTALLED_APPS

如果它不返回 True,则意味着您没有在 INSTALLED_APPS 中正确添加 'django_extensions',这将是 Django 找不到该命令的唯一原因。

于 2012-03-28T13:31:35.027 回答
5

Actually, if you look at your manage.py's code, you will notice that it sets DJANGO_SETTINGS_MODULES according to your current site: let say "mysite.settings". If you want your manage.py to list additional extensions (e.g. ones from django-extensions or django-evolution) then you must add your project-root's folder to your python path, if not you will only get the bascc manage.py commands.

于 2013-01-25T18:00:21.410 回答