Services Blog Français

Never hardcode absolute paths

| by jpic | python django best-practice

This is nonono:

    STATIC_ROOT = '/home/coat/www/site/app/static/'

Never hardcode absolute paths, you’re just making your settings file less portable and probably killing kittens. Adapt this to your needs:

    import os.path
    import posixpath

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

    STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')

    # fix STATICFILES_DIRS too
    # and TEMPLATE_DIRS

They trust us

Contact

logo