Last active
October 2, 2023 12:25
-
-
Save FMCorz/a8a42f2f8d6240715c881b8a768cfe4a to your computer and use it in GitHub Desktop.
Django standalone script #python #django
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
# 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