Login

modular settings / site settings

Author:
mfechtner
Posted:
June 25, 2010
Language:
Python
Version:
1.2
Score:
0 (after 0 ratings)

a snippet to split up settings or to reuse and modify settings

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
if u want to split ur settings.py
or use custom settings per site

lets say it looks like this:

'project/settings.py'

just create a folder named 'settings'.
create an '__init__.py'
copy the content of 'settings.py' to '__init__.py'
delete the ol' bastard named 'settings.py'

now it should look like

'project/settings/__init__.py'

if u want to put database settings in a seperate file.
create 'db.py' in 'settings' ...

'project/settings/__init__.py'
'project/settings/db.py'

and simply add this line to '__init__.py':
'from db import *'

to resuse an existing 'settings.py' simply import it in ur custom 'settingsxXXX.py' with:

'from settings import *'

test it with './manage.py runserver --settings settingsxXXX'

More like this

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

Comments

Please login first before commenting.