I have a typical Django web app. I want to create a separate project, with its own virtualenv, and make use of the ORM to create new entries in the DB.
There are a lot of resources on explaining how to do this, including this entry from the docs. So I wrote a script as follows:
# Add Django project directory to path, so that I can
# import the models
import sys
sys.path.append("/path/to/django/project")
# Import my settings file from the Django project
from django_proj import settings as django_settings
import django
from django.conf import settings
if not settings.configured:
settings.configure(django_settings)
django.setup()
When I try to run it this way, I get the following error:
AttributeError: 'module' object has no attribute 'LOGGING_CONFIG'
I believe this is due to the fact that I don't specify a LOGGING_CONFIG
explicitly in my settings. I rely on the default value.
My configuration clearly works when I run it via python manage.py
. What is the issue with this additional setup that's causing problems?
Thanks!
Try:
import os
import sys
import django
sys.path.append('/path/to/django_project')
#from django_project import *
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings')
django.setup()
This worked for me. Hope it helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With