I recently install django-extensions
, ptpython
and django-browser-reload
packages on a project, it is convenient packages to Django developer.
Installation
install it with pip:
pip install django-extensions ptpython django-browser-reload
or reference it in your package manager, I personaly prefer to set it in dev-requirements.txt
and activate them only for DEVELOPMENT environment : configuration proposed below.
Then, you’ll have to declare it on the INSTALL_APPS
of your application
if ENVIRONMENT == "development":
INSTALLED_APPS.extend(
[
"django_extensions",
"django_browser_reload",
]
)
SHELL_PLUS_PRINT_SQL = True
SHELL_PLUS_PRINT_SQL
will print the SQL query on your shll_plus
: exemple below
Configure your middlewares :
if "django_browser_reload" in INSTALLED_APPS:
MIDDLEWARE.extend(
[
"django_browser_reload.middleware.BrowserReloadMiddleware",
]
)
and you urls.py
if "django_browser_reload" in settings.INSTALLED_APPS:
urlpatterns.extend(
[
path("__reload__/", include("django_browser_reload.urls")),
]
)
Features
Shell plus
Main feature of django is the command shell_plus
. It will load yours models and some package by default.
Using ptpython, your prompt will provide coloration and auto-completion :
$> python manage.py shell_plus
Hot reload
django-browser-reload
will provide hotreload. Everytime your application is reloaded, your page in your browser is reloaded to. this avoid a lot of F5
.
Conclusion
Those package are very useful for django developer.
Django-extensions as a lot more helper command, to dig in, please visit command extensions page.