Serplat
Serplat

Reputation: 4447

Where should I put configuration details? [Python]

I'm fairly new to Python and Django, and I'm working on a webapp now that will be run on multiple servers. Each server has it's own little configuration details (commands, file paths, etc.) that I would like to just be able to store in a settings file, and then have a different copy of the file on each system.

I know that in Django, there's a settings file. However, is that only for Django-related things? Or am I supposed to put this type of stuff in there too?

Upvotes: 1

Views: 220

Answers (3)

Alex Kuhl
Alex Kuhl

Reputation: 1824

This page discusses yours and several other situations involving configurations on Django servers: http://code.djangoproject.com/wiki/SplitSettings

Upvotes: 2

awesomo
awesomo

Reputation: 8816

There isn't a standard place to put config files. You can easily create your own config file as needed though. ConfigParser might suit your needs (and is a Python built-in).

Regardless of the format that I use for my config file, I usually have my scripts that depend on settings get the config file path from environment variables

(using bash):

export MY_APP_CONFIG_PATH=/path/to/config/file/on/this/system

and then my scripts pick up the settings like so:

import os
path_to_config = os.environ['MY_APP_CONFIG_PATH']

Upvotes: 1

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798744

It's for any type of settings, but it's better to put local settings in a separate file so that version upgrades don't clobber them. Have the global settings file detect the presence of the local settings file and then either import everything from it or just execfile() it.

Upvotes: 1

Related Questions