我的设置文件如下所示,
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR,'static')
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static', 'static_dirs'),)
MEDIA_URL = '/static/images/'
MEDIA_ROOT = '/Users/bhargavsaidama/5ai/source/static/images/'
#MEDIA_ROOT = os.path.join(BASE_DIR,'static', 'images') (tried this too)
我的html加载页面如下,注意:我这里直接使用文件路径
索引.html:
<!DOCTYPE html>
{% load staticfiles %}
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
我的实际 html 文件是:
{% extends "index.html" %}
{% block content %}
<div class="content">
<img src ='/Users/bhargavsaidama/5ai/source/5ai/static/images/Indian-economy.jpg' alt="My image">
<h2 id = "title"><font face = "Comic sans MS"> {{ post.title }} </font></h2>
{% for sub_text in post.content %}
<p id = "data"><font face = "Comic sans MS" size="+0.3"> {{ sub_text }} </font></p>
{% endfor %}
</div>
{% endblock %}
即使我尝试使用:
<img src ='Indian-economy.jpg' alt="My image">
....但没有运气
如果我尝试使用普通的 html 文件,可以说:
<html>
<p> this is bhargav sai</p>
<img src= '/Users/bhargavsaidama/5ai/source/5ai/static/images/Indian-economy.jpg' alt = 'my image'>
</html>
谁可以帮我这个事?