我正在django做一个项目。我能够实现html页面,但无法显示该页面的图像。
<img src= "home/ashish/PycharmProjects/django/webapp/family/static/images/error-img.png" />
显示错误为
Resource interpreted as Image but transferred with MIME type text/html
当我点击网址时,请求网址为:http://127.0.0.1:8002/home/ashish/PycharmProjects/django_webapp/family/static/images/error-img.png
如果我将src设为在线图像,它可以正常工作。
setting.py
STATIC_URL = '/static/' # You may find this is already defined as such.
STATICFILES_DIRS = (
STATIC_PATH,)
MEDIA_URL = '/media/'
所有图片都在app / static / images内。
谢谢
答案 0 :(得分:0)
您还没有在urls.py文件中定义静态文件URLconf。您可以为开发服务器使用定义它们,如下所示:
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
...
urlpatterns += staticfiles_urlpatterns()
然后您可以在以下位置查看静态文件:
http://127.0.0.1:8002/static/images/error-img.png