Afternoon wrote:


I'd like to have a solution to this problem too.

My specific problem is that I have a bunch of sites in development on my laptop:

    http://localhost/coolsite/
    http://localhost/boringsite/
    http://localhost/newhomepage/

And these then get deployed to production servers:

    http://coolsite.com/
    http://boringsite/newcoolthing/
    http://homepage.org/


Well, if all of your sites are separate django projects that's easy, you 
already have a (static) dir pointed by your
MEDIA_URL, so:

1. Store file system path to your project in the SITE_ROOT variable in the 
config file.

2. Anywhere when you must supply a path (like ImageField, MEDIA_ROOT, etc.), 
use os.path.join(SITE_ROOT, 'foo').

3. Put all of your static files under /media/ and always use URLs like this 
/media/img/foo.png, /media/js/foo.js, etc.

4. Setup URLs:
        - Config file:
                ADMIN_MEDIA_PREFIX = '/admin-media/'
                MEDIA_URL = os.path.join(SITE_ROOT, 'media')
                MEDIA_PREFIX = '/media/'

        - Apache:
                Alias /media/ "<SITE_ROOT>/media/"
                Alias /admin-media/ "<django root>/django/contrib/admin/media/"

        - Lighttpd:
            alias.url = (
              "/media/" => "<SITE_ROOT>/media/",
              "/admin-media/" => "<django root>/django/contrib/admin/media/",
            )


5. Also you can use this in your main url conf to make this files accessible 
when using django-admin.py runserver (from
another post on the list) - admin media files are handled automagically:

from django.conf.settings import LOCAL_DEV, SITE_ROOT
if LOCAL_DEV:
   import os
   urlpatterns += patterns('',
       (r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': 
os.path.join(SITE_ROOT, 'media')}),
  )
#

I'm using a LOCAL_DEV var to distinguish between local runserver 
(DEBUG=LOCAL_DEV=True), staging server (DEBUG=True,
LOCAL_DEV=False) and production server (DEBUG=LOCAL_DEV=False).

With this setting I have a local server, a staging server and a production 
server setup which only differs in SITE_ROOT
(sometimes, because I tend to replicate directory structure from my production 
server), LOCAL_DEV and DEBUG variables.

--
Nebojša Đorđević - nesh
Studio Quattro - Niš - SCG
http://studioquattro.biz/forum/

http://djnesh.blogspot.com/  |  http://djnesh-django.blogspot.com/ |
http://djangoutils.python-hosting.com/
Registered Linux User 282159 [http://counter.li.org]









Reply via email to