Last active
December 14, 2023 05:35
-
-
Save noopurphalak/b3ae80b3be941e6c97ef0a135c1c8861 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A script that's needed to setup django if it's not already running on a server. | |
# Without this, you won't be able to import django modules | |
import django | |
import os | |
import sys | |
# Find the project base directory | |
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
# Add the project base directory to the sys.path | |
# This means the script will look in the base directory for any module imports | |
# Therefore you'll be able to import analysis.models etc | |
sys.path.insert(0, BASE_DIR) | |
# The DJANGO_SETTINGS_MODULE has to be set to allow us to access django imports | |
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "src.settings") | |
# Allow queryset filtering asynchronously when running in a Jupyter notebook | |
os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true" | |
# This is for setting up django | |
django.setup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment