I want to set a variable ENV in settings.py like:
import sys, os
path_django_site = os.path.join(os.path.dirname(__file__), "../../")
sys.path.append(path_django_site)
os.environ['DJANGO_SETTINGS_MODULE'] = 'pjt1.settings.dev'
ENV = os.environ['DJANGO_SETTINGS_MODULE']
So that in my spider project,I can write code like this:
if ENV =='pjt1.settings.dev':
obj = Group.objects.filter(id__lte=10)
print 'this is test'
elif ENV =='pjt.settings.prod':
obj = Group.objects.all()
print 'This is normal environvent'
is it posible? Please guide me. Thank you.
I'm not sure I understand the actual question, but you can set any variable in your settings.py and use it like this:
# your wsgi file probably includes something like this
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pjt1.settings.dev")
# settings.py
ENV = os.environ['DJANGO_SETTINGS_MODULE']
# other files
from django.conf import settings
if settings.ENV == 'pjt1.settings.dev':
...
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