Django Standalone Script

后端 未结 4 1476
死守一世寂寞
死守一世寂寞 2020-12-01 07:43

I am trying to access my Django (v1.10) app DB from another python script and having some trouble doing so.

This is my file and folder structure:

sto         


        
4条回答
  •  忘掉有多难
    2020-12-01 08:23

    I found the django-extensions package to be most useful. You can find it here

    After installation and adding it to the installed apps, all you need to do is to create a directory called scripts, create a file and run it by python manage.py runscript file_name

    Just remember that the file must have an entry point. That entry point is a method called run which has to be present and will run once you run python manage.py runscript file_name in the terminal

提交回复
热议问题