Login

Setting distinction between development and public server

Author:
Archatas
Posted:
March 8, 2007
Language:
Python
Version:
Pre .96
Score:
1 (after 7 ratings)

If your code is under source control and you develop locally and then publish that globally, you might need to modify the settings file after each update to ensure the system paths and database settings are correct.

This simple solution helps to distinguish development server from the public server. And you won't need to care about modifying files on the public server anymore.

Create a file called dev_environment.py in your site-packages directory of the development server only (do not put it under source control). Then use the following lines in the beginning of your files, you want to check whether you are in the development environment.

try: 
    from dev_environment import *
except:
    is_dev_environment = False

Then for example, you can set the database settings according the environment:

if is_dev_environment:
    DATABASE_NAME = "test"
    DATABASE_USER = "root"
    DATABASE_PASSWORD = ""
else:
    DATABASE_NAME = "publicproject"
    DATABASE_USER = "projectuser"
    DATABASE_PASSWORD = "ahl3379ljkasd"
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# dev_environment.py at site-packages
"""
For checking whether the code is executed on the public or local server
>>> try: 
...     from dev_environment import *
... except:
...     is_dev_environment = False
...
"""
is_dev_environment = True

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 11 months, 2 weeks ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months, 3 weeks ago
  3. Serializer factory with Django Rest Framework by julio 1 year, 6 months ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 7 months ago
  5. Help text hyperlinks by sa2812 1 year, 8 months ago

Comments

Please login first before commenting.