# HG changeset patch # User Branko Majic <branko@majic.rs> # Date 2013-08-17 17:29:52 # Node ID 4948802118275ec0e50c3551a4c58d44bb65fada # Parent ab6de89ec914e7069a0879ab666b4e3bb92ec21d DMT-1: Calculate media and static files root directories automatically. Set the URLs for them to /media/ and /static/. Enable the Django admin app by default. diff --git a/project/project_name/settings/base.py b/project/project_name/settings/base.py --- a/project/project_name/settings/base.py +++ b/project/project_name/settings/base.py @@ -5,6 +5,12 @@ # project. Do not put any site-specific settings here. # +from os import path + +# Determine the Django project root directory. +PROJECT_ROOT = path.dirname(path.dirname(path.abspath(__file__))) +ASSETS_ROOT = path.normpath(path.join(PROJECT_ROOT, "assets")) + # Language code for this installation. All choices can be found here: # http://www.i18nguy.com/unicode/language-identifiers.html LANGUAGE_CODE = 'en-us' @@ -22,20 +28,17 @@ USE_L10N = True # If you set this to False, Django will not use timezone-aware datetimes. USE_TZ = True -# Absolute filesystem path to the directory that will hold user-uploaded files. -# Example: "/var/www/example.com/media/" -MEDIA_ROOT = '' +# Absolute filesystem path to the directory that will hold user-uploaded +# files. Calculated based on project root. +MEDIA_ROOT = path.normpath(path.join(ASSETS_ROOT, "media")) # URL that handles the media served from MEDIA_ROOT. Make sure to use a # trailing slash. -# Examples: "http://example.com/media/", "http://media.example.com/" -MEDIA_URL = '' +MEDIA_URL = '/media/' -# Absolute path to the directory static files should be collected to. -# Don't put anything in this directory yourself; store your static files -# in apps' "static/" subdirectories and in STATICFILES_DIRS. -# Example: "/var/www/example.com/static/" -STATIC_ROOT = '' +# Absolute path to the directory static files should be collected to. Calculated +# based on project root. +STATIC_ROOT = path.normpah(path.join(ASSETS_ROOT, "static")) # URL prefix for static files. # Example: "http://example.com/static/", "http://static.example.com/" @@ -92,7 +95,7 @@ INSTALLED_APPS = ( 'django.contrib.messages', 'django.contrib.staticfiles', # Uncomment the next line to enable the admin: - # 'django.contrib.admin', + 'django.contrib.admin', # Uncomment the next line to enable admin documentation: # 'django.contrib.admindocs', ) diff --git a/project/project_name/urls.py b/project/project_name/urls.py --- a/project/project_name/urls.py +++ b/project/project_name/urls.py @@ -1,8 +1,8 @@ from django.conf.urls import patterns, include, url # Uncomment the next two lines to enable the admin: -# from django.contrib import admin -# admin.autodiscover() +from django.contrib import admin +admin.autodiscover() urlpatterns = patterns('', # Examples: @@ -13,5 +13,5 @@ urlpatterns = patterns('', # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), # Uncomment the next line to enable the admin: - # url(r'^admin/', include(admin.site.urls)), + url(r'^admin/', include(admin.site.urls)), )