Using Django in Jupyter Notebook

Oct 18, 2018 · 1 min read

In my last story, I related how to install a kernel in a virtual environment in order to run Jupyter from there.

This was a necessary step to run Django in Jupyter Notebook

So now to run Django, we need to set a few more things

In the Notebook, we need to initialize Django this way:

import os# this environment variable points to the 'settings' module 
# in the Django app.
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings")
# maybe not be necessary if you hard coded you DB URL in settings,
# but mine it pulled from the DATABASE_URL environment variable
# and then...
import django

That’s it!


Written by

Product Manager, Solution Architect, Entrepreneur, passionate about making sense of data.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade