title: How do I set up Jupyter/IPython Notebook for Django?
body: <p>I have been using the method described in <a href="https://andrewbrookins.com/python/using-ipython-notebook-with-django/" rel="noreferrer">this post</a> for setting up IPython Notebook to play nicely with Django. The gist of the method is to create an IPython extension which sets the DJANGO_SETTINGS_MODULE and runs django.setup() when IPython starts.</p>
  
  <p>The code for the extension is:</p>
  
  <pre><code>def load_ipython_extension(ipython):
      # The `ipython` argument is the currently active `InteractiveShell`
      # instance, which can be used in any way. This allows you to register
      # new magics or aliases, for example.
      try:
          import os
          os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
          import django
          django.setup()
      except ImportError:
          pass
  </code></pre>
  
  <p>With a recent upgrade to Jupyter Notebook this setup is now broken for me. I am able to run Django code in the Jupyter notebook by adding a similar bit of code to the first cell of the notebook. However, I was not able to figure out how to get Jupyter to run the extension automatically so I would not have to do this again for each and every notebook I am creating.</p>
  
  <p>What should I do to get Django and Jupyter to play nicely?</p>
  
  <p><strong>UPDATE:</strong>
  For @DarkLight - I am using Django 1.8.5 with Jupyter 1.0.0. The code I run in the notebook is:</p>
  
  <pre><code>import os, sys
  sys.path.insert(0, '/path/to/project')
  os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settingsfile")
  import django
  django.setup()
  </code></pre>