map_path function for settings.py

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#settings.py

import os

def map_path(directory_name):
    return os.path.join(os.path.dirname(__file__), directory_name).replace('\\', '/')

STATIC_ROOT = map_path('static')
TEMPLATE_DIRS = map_path('templates')

"""
This would find the "static" and "templates" directories (given the structure below) without having to hard code the paths in settings.py. This is very useful if you switch environments from Windows to Mac or Linux from say a PC workstation at your office to a Mac at home.

Example Directory Structure:
my_app/
settings.py
templates/
static/
    images/
    css/
    js/
"""

More like this

  1. Load a local settings file for dev/test environments by menendez 4 years, 9 months ago
  2. Database file storage by powerfox 4 years, 3 months ago
  3. Dynamically specify TEMPLATE_DIRS by ajs17 6 years, 2 months ago
  4. Template context processor to make the settings.py values available in templates by tamizhgeek 2 years ago
  5. PyCallTag - Directly call python function or attribute of a module by limodou 6 years, 2 months ago

Comments

(Forgotten your password?)