Django on Heroku - Broken Admin Static Files

前端 未结 9 505
天命终不由人
天命终不由人 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:28

    just add these instead

    from django.contrib.staticfiles.urls import staticfiles_urlpatterns
    urlpatterns += staticfiles_urlpatterns()
    

    using django 1.4.1

    0 讨论(0)
  • 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<path>.*)$', '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.

    0 讨论(0)
  • 2020-12-24 15:32

    If you are deploying to Heroku without using whitenoise (which I would suggest), definitely use dj_static https://pypi.python.org/pypi/dj-static!

    I spent the past 3 hours trying to serve my files to heroku and dj_static worked within a matter of 2 minutes.

    0 讨论(0)
提交回复
热议问题