Skip to content

Instantly share code, notes, and snippets.

@develmaycare
Created May 7, 2018 13:40
Show Gist options
  • Save develmaycare/1d03f21f35e40418ec47f7814103e30a to your computer and use it in GitHub Desktop.
Save develmaycare/1d03f21f35e40418ec47f7814103e30a to your computer and use it in GitHub Desktop.
Standalone Django scripting.
#! /usr/bin/env python
import os
import sys
# Define the path to the project.
PROJECT_PATH = os.path.abspath(os.path.join("example", "source"))
# Let Django know where things are.
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "main.settings")
sys.path.append(PROJECT_PATH)
# Change directory for relative paths to work.
os.chdir(PROJECT_PATH)
# Initialize Django.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
# Start scripting.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment