Django on Heroku - Broken Admin Static Files

前端 未结 9 614
天命终不由人
天命终不由人 2020-12-24 14:37

I have a Django app running on Heroku/Cedar, configured as per the instructions at https://devcenter.heroku.com/articles/django

Using gunicorn as per Heroku\'s instr

9条回答
  •  粉色の甜心
    2020-12-24 15:29

    create 'static' folder into your 'project_directory'.

    set the 'STATIC_ROOT' path in 'settings.py' file which can serve your admin-site's static files.

    STATIC_ROOT = (os.path.join(os.path.dirname(__file__), '..', 'static'))
    

    Add STATIC_ROOT in '/urls.py'

    from django.conf import settings
        urlpatterns += patterns('',
            url(r'^static/(?P.*)$', 'django.views.static.serve', {
                'document_root': settings.STATIC_ROOT,
            }),
        )
    

    Run the following command that will copy all the admin static files into project's static folder.

    python manage.py collectstatic
    

    Now do git add, commit and push heroku master.

提交回复
热议问题