Atom `script` add-on doesn't recognize Django Model/settings when running a script

后端 未结 1 664
感动是毒
感动是毒 2021-01-28 15:32

It seems I run into some dependencies issues when trying to run a python script within my Django based web application using the atom add-on script.

I would

相关标签:
1条回答
  • 2021-01-28 15:48

    Your models are inside your apps, and your apps are inside your settings (INSTALLED_APPS), so you should configure the django's settings before you can access them.

    Just add these before importing your models:

    import django
    django.setup()
    

    You should also set DJANGO_SETTINGS_MODULE environment varialbe to specify your settings file; or use django.configure if you prefer (docs).

    0 讨论(0)
提交回复
热议问题