/ components / paddock / notebooks / django_initializer.py
django_initializer.py
 1  # A script that's needed to setup django if it's not already running on a server.
 2  # Without this, you won't be able to import django modules
 3  import os
 4  import sys
 5  
 6  import django
 7  
 8  # Find the project base directory
 9  BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
10  
11  # Add the project base directory to the sys.path
12  # This means the script will look in the base directory for any module imports
13  # Therefore you'll be able to import analysis.models etc
14  sys.path.insert(0, BASE_DIR)
15  
16  # The DJANGO_SETTINGS_MODULE has to be set to allow us to access django imports
17  os.environ.setdefault("DJANGO_SETTINGS_MODULE", "paddock.settings")
18  
19  #  Allow queryset filtering asynchronously when running in a Jupyter notebook
20  os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"
21  
22  # This is for setting up django
23  django.setup()