Django - uwsgi.py to run a python script

I need to run a script into my Django project.

I'm using this approach, that works, but I'm looking for more valid alternatives.

uwsgi.py

import os
from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MyApp.settings")
application = get_wsgi_application()

__import__('myapp.script')
import os

os.environ = {'DJANGO_SETTINGS_MODULE': 'MyApp.settings'}

import django

django.setup()

def main():

    # some script using django db
    pass

main()

I don't like to use this approach because every time I need to set DJANGO_SETTINGS_MODULE, because I also want to run it locally.

I prefere using the runscript. So, there is a way to call the manage.py from the wsgi module in order to use the runscript to run the script.py?

Or, do you know another approach like the uwsgi.ini or something else?

Back to Top