Django django-extensions commands unavailable ( graph_models )
Question:
I’m trying to install django-extensions + graphviz + pygraph but i can’t.
I have done the following steps ( under Ubuntu ):
sudo apt-get install graphviz libgraphviz-dev graphviz-dev python-pygraphviz
in the project virtualenv (running python 2.7.2+):
source <path to virtualenv>/bin/activate
pip install django django-extensions
if i run
which python
it selects the python in my virtualenv, so the python i’m using is the right one.
in the virtualenv’s site-package i have pygraphviz and django-extensions
python manage.py shell
import django_extensions
import pygraphviz
RUNS OK
in my django project i have added ‘django_extensions’ in my INSTALLED_APPS
But when i run
python manage.py help
i can’t see the commands and they are unavailable.
python manage.py graph_models -a -g -o model.png
Unknown command: 'graph_models'
Type 'manage.py help' for usage.
How can I fix this ?
Thanks!
Answers:
Run this in manage.py shell:
from django.conf import settings; 'django_extensions' in settings.INSTALLED_APPS
If it doesn’t return True, then it means that you didn’t add ‘django_extensions’ properly in INSTALLED_APPS, and that would be the only reason why Django doesn’t find the command.
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.
I had it under everything else in settings.py
INSTALLED_APPS
. Moving it at the top fixed it:
From
INSTALLED_APPS = [
...
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_extensions',
]
TO
INSTALLED_APPS = [
'django_extensions',
...
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
I’m trying to install django-extensions + graphviz + pygraph but i can’t.
I have done the following steps ( under Ubuntu ):
sudo apt-get install graphviz libgraphviz-dev graphviz-dev python-pygraphviz
in the project virtualenv (running python 2.7.2+):
source <path to virtualenv>/bin/activate
pip install django django-extensions
if i run
which python
it selects the python in my virtualenv, so the python i’m using is the right one.
in the virtualenv’s site-package i have pygraphviz and django-extensions
python manage.py shell
import django_extensions
import pygraphviz
RUNS OK
in my django project i have added ‘django_extensions’ in my INSTALLED_APPS
But when i run
python manage.py help
i can’t see the commands and they are unavailable.
python manage.py graph_models -a -g -o model.png
Unknown command: 'graph_models'
Type 'manage.py help' for usage.
How can I fix this ?
Thanks!
Run this in manage.py shell:
from django.conf import settings; 'django_extensions' in settings.INSTALLED_APPS
If it doesn’t return True, then it means that you didn’t add ‘django_extensions’ properly in INSTALLED_APPS, and that would be the only reason why Django doesn’t find the command.
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.
I had it under everything else in settings.py
INSTALLED_APPS
. Moving it at the top fixed it:
From
INSTALLED_APPS = [
...
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_extensions',
]
TO
INSTALLED_APPS = [
'django_extensions',
...
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]