I've done a couple of Django apps so far, and one thing that always annoys me is having to manually set DEBUG in my settings.py when moving from development to production, or vice versa.
Since I'm always developing on my localhost, I know that I always want DEBUG to be True when running on localhost. I also know that DEBUG should always be False when running on my production server. Fortunately, Python makes quick work of this. In your settings.py file:
import socket if socket.gethostname() == 'productionserver.com': DEBUG = False else: DEBUG = True
That's pretty much it. Saves me a ton of time.
Yes, I'm that lazy.
5 Comments
DEBUG = socket.gethostname() != 'productionserver.com'
Since these could be more than one machine, I add this in my settings.py:
import platform
DEPLOYMENT_SERVERS = ('server1.com', 'bla.blub.com',)
DEBUG = platform.node() not in DEPLOYMENT_SERVERS
You see, I'm lazy, too ;-)
Ah, interesting! Very cool :)
Thanks!
We have a lot of settings that are different in deployment and development so we created a file called localsettings.py, set DEBUG=True and whatever else you need, make sure it's ignored by your version control system.
Add this to the end of your settings.py file
try:
import localsettings
except:
pass
Eric wrote a great blog post on extending debug functionality to production servers based on admin status or IP. Check it out!
Nick
yeah, I'm just using a separate local_settings.py, but this is a cool idea (you're not the only one who's that lazy, trust me)
Post new comment