Skip to content

Instantly share code, notes, and snippets.

@miraculixx
Created September 5, 2016 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miraculixx/c18affe36756591923d3a67130fe0c05 to your computer and use it in GitHub Desktop.
Save miraculixx/c18affe36756591923d3a67130fe0c05 to your computer and use it in GitHub Desktop.
start ipython notebook including django
import os
if os.environ.get('DJANGO_SETTINGS_MODULE'):
  print "Initializing Django..."
  if not os.path.exists('app/settings.py'):
      os.chdir('..')
  print "(in directory %s)" % os.getcwd()
  try:
    from django_extensions import management
  except BaseException as e:
    print "Could not initialize django -- stacktrace fyi only"
    import traceback
    import sys
    traceback.print_exc()
    print sys.path
  else:
    c.InteractiveShellApp.extensions = ['django_extensions.management.notebook_extension']
else:
 print "DJANGO_SETTINGS_MODULE %s" % ('not set' if 'DJANGO_SETTINGS_MODULE' not in os.environ else 'empty')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment