DISQUS

bart's blog: Two simple techniques to make your Django projects ultra portable

  • SmileyChris · 1 year ago
    ROOT_DIR = os.path.join(os.path.dirname(__file__)) uses join incorrectly. The point of os.path.join is to join path components in a generic way that works across operating systems: Here's what you should use:

    PROJECT_ROOT = os.path.dirname(__file__)
    MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'media')


    And a tip for your urls.py for nicely serving static files in development mode:
    # Static media
    import sys
    if 'runserver' in sys.argv:
    ----from django.conf import settings
    ----urlpatterns += patterns('django.views.static',
    --------(r'^%s(?P<path>.*)' % settings.MEDIA_URL[1:], 'serve', {'document_root': settings.MEDIA_ROOT}),
    ----)

    Edit: indented with dashes to preserve spacing
  • Bartek · 1 year ago
    Hey thanks, good to know that! I'll update my post to reflect that .. and of
    course use it from now on :)
  • SmileyChris · 1 year ago
    Note, you're still hard coding the '/' in your post. That's where you should be using os.path.join
  • Bartek · 1 year ago
    Doh, that's what I get when I am in a rush. Fixed my post up there
  • John · 1 year ago
    Great tips! Changing my settings files now.