Django template image won't load

前端 未结 4 1817
轮回少年
轮回少年 2020-12-22 09:23

Image won\'t load. I see o broken image icon. I use the static tag. I also tried giving the absolute path and never worked.I used the alt tag but still i can only see the br

4条回答
  •  长情又很酷
    2020-12-22 09:38

    Are you in a production or development environment?

    Can you access the /static/images/logo.png by typing it into the browser?

    When in development, where debug is on I add this to the end of the urls.py file:

    from django.conf import settings
    from django.conf.urls.static import static
    from django.contrib.staticfiles.urls import staticfiles_urlpatterns
    
    if settings.DEBUG:
        urlpatterns += staticfiles_urlpatterns()
        urlpatterns += static(settings.MEDIA_URL,
                          document_root=settings.MEDIA_ROOT)
    

    See here: https://docs.djangoproject.com/en/1.5/ref/contrib/staticfiles/#other-helpers

提交回复
热议问题