How to call Django environment in a Python script

created at 07-17-2021 views: 2

Call the Django environment in a Python script:

import os

if __name__ =='__main__':
     #Load the project environment, "App.settings" is the project configuration file
     #App must be your project name
     os.environ.setdefault("DJANGO_SETTINGS_MODULE", "App.settings")
     #Load django
     import django
     #Start django

     #Start running your script file
     #Specific code

Note: App is the name of the project

created at:07-17-2021
edited at: 07-17-2021: