Minimal Django script setup

By | February 10, 2021
import os, sys, pathlib
# if script is in on 1 level deep
# sys.path.append(str(pathlib.Path(__file__).parents[1].absolute()))
sys.path.append(str(pathlib.Path(__file__).absolute()))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "main.settings")
import django
django.setup()

# import your django models
# do your django work

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.