Skip to content

Utility to convert a python script into a standalone django script.

License

Notifications You must be signed in to change notification settings

kasun/django-sa

Repository files navigation

django-sa

Utility to convert a python script into a standalone django script. For Python2/Python3 and Django 1.7+

Installation

Install:

pip install django-sa

Implementation Notes with Short Examples

What happens when you try to run a script with django code in it?:

python backup.py
Traceback (most recent call last):
File "backup.py", line 6, in <module>
↓
↓
↓
django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

django-sa way:

+ The script needs to be run from the project root directory
+ This uses the default django settings file which is in project_dir/settings.py
from django_sa import setup_django
setup_django(__file__)

# django code

Using a different django settings file:

from django_sa import setup_django
setup_django(__file__, 'my_project.settings.production')

# django code

About

Utility to convert a python script into a standalone django script.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages