PROJECTS NOTES HOME

Run django-orm queries over jupyter notebook with django-extensions package

Can use a fancy shell(ipython, print sql, jupyter, etc)

https://django-extensions.readthedocs.io/en/latest/index.html

A few of the subpages below use it, kind of nice

To use them properly, do this:

pip install django-extensions Add "django_extensions", to settings.py installed apps section.

1 Shell_plus

pip install ipython - will use ipython by default when running shell - https://django-extensions.readthedocs.io/en/latest/shell_plus.html#

https://django-extensions.readthedocs.io/en/latest/shell_plus.html#sql-queries - python manage.py shell_plus --print-sql

pip install jupyter So now can run python manage.py shell_plus --lab

If you want to run –notebook, downgrade to lower version:

pip install notebook==6.5.6

https://gist.github.com/EtsuNDmA/dd8949061783bf593706559374c8f635

If getting such errors - https://github.com/django-extensions/django-extensions/issues/1533 async bs,

Same issue described here - https://stackoverflow.com/questions/59119396/how-to-use-django-3-0-orm-in-a-jupyter-notebook-without-triggering-the-async-con

then try to add one more thing to settings.py:

os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"

total config that needs to be added:

NOTEBOOK_DIR = BASE_DIR / "notebooks" # save notebooks in a dedicated folder
os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true" # allow to run ORM queries