Running a Python script outside of Django

前端 未结 7 1923
后悔当初
后悔当初 2021-01-30 03:22

I have a script which uses the Django ORM features, amongst other external libraries, that I want to run outside of Django (that is, executed from the command-line).

Edi

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-30 03:42

    from           import settings          #your project settings file
    from django.core.management  import setup_environ     #environment setup function
    
    setup_environ(settings)
    
    #Rest of your django imports and code go here
    

提交回复
热议问题