Skip to content

Instantly share code, notes, and snippets.

@FMCorz
Last active October 2, 2023 12:25
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FMCorz/a8a42f2f8d6240715c881b8a768cfe4a to your computer and use it in GitHub Desktop.
Save FMCorz/a8a42f2f8d6240715c881b8a768cfe4a to your computer and use it in GitHub Desktop.
Django standalone script #python #django
# Standalone Django script
#
# Ideal for quickly testing some code.
#
# 1. Place at the root of your project
# 2. Edit the variable PROJECT_NAME
# 3. Run it: python sandbox.py
import os
PROJECT_NAME = 'myprojectname'
def main():
# All imports here.
# from django.db import models
# from myprojectname.models import MyModel
# Whatever you need here.
print('Hello world!')
if __name__ == '__main__':
os.environ.setdefault('DJANGO_SETTINGS_MODULE', '%s.settings' % PROJECT_NAME)
import django
django.setup()
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment