Skip to content

Instantly share code, notes, and snippets.

@FMCorz
Last active Dec 11, 2020
Embed
What would you like to do?
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