Install it with pip command and then include it in INSTALLED_APPS in settings.py file. Notice that in INSTALLED_APPS django_extensions is written with _ (underscore) while for pip install command it is specified with "-" (dash) character.
$ pip install django-extensions # notice "-" character $ cat settings.py ... INSTALLED_APPS = [ ... django_extensions, # notice "_" character ... ] ...
Let's review top 5 most practical commands:
The django extension that I personally find most useful is show_urls.
show_urls prints all routes used by your django application. I found it very useful for discovering not documented routes added by 3rd party apps. It is also immediately available one you install django extensions app without external dependencies (other commands may require additional modules to install). It displays information in URL - View - url_name format:
/pages/_util/login/ django.contrib.auth.views.LoginView wagtailcore_login /privacy lessons.views.PageView privacy /subscribe lessons.views.subscribe subscribe
This one is very cool, it adds auto-complete and syntax highlighting in django shell. It provides a lot of fun when experimenting with models and functions in interactive mode. shell_plus relies on
$ pip install ipython bpython
Then start shell_plus session based on bpython provider:
$ python manage shell_plus --bpython
Similarly you can choose for ipython based shell. It provides little bit different look and feel, as I said, experiment with both to decide which one suites you better.
$ python manage shell_plus --ipython
$ sudo pacman -S graphviz # on archlinux $ sudo apt-get install graphviz # on ubuntu $ pip install pygraphviz
To generate a png image with all models of say, lessons app, use command:
$ python manage.py graph_models lessons -o lessons.png
This command is usual django's runserver command with one neat feature added - it includes werkzeug's interactive debugger. Basically if you got a python's exception, beside displaying exception stack trace, it adds a interactive debugger directly in the context of that exception in web browser. Using this nice feature in development/DEBUG=True mode only. As of writing this lesson, I was unable to team together django latest version 3.0.3 and werkzeug latest version 1.0.0. To make runserver_plus command recognize and work with werkzeug I needed to downgrade werkzeug to 0.16 version.
- Lesson #16
- Feb 08, 2020