Using Django in Jupyter Notebook

Using Django in Jupyter Notebook

To explore your Django models in Jupyter Notebook, you can use the following setup.

  1. Install django-extensions
pip install django-extensions
  1. Include django-extensions in your settings
INSTALLED_APPS += ['django_extensions']
  1. Start Django server
python manage.py shell_plus --notebook
  1. Then, I usually add DJANGO_ALLOW_ASYNC_UNSAFE to debug locally. Not recommended on production databases.
import os
os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"
  1. Now import your django models
from app.models import User

for user in User.objects.all():
    print(user)

10. Mar 2021