HTML页面:
<body>
{% load static %}
<section class="hero is-success is-fullheight">
<div class="hero-body">
<div class="container has-text-centered">
<div class="column is-4 is-offset-4">
<h3 class="title has-text-grey">Login</h3>
<div class="box">
<figure class="avatar">
<img src="{% static 'images/abc.png' %}">
</figure>
Settings.py配置
# Static files (CSS, JavaScript, Images)STATIC_URL = '/static/'
STATIC_URL = '/static/'
#STATIC_URL = os.path.join(BASE_DIR, "static/")
STATIC_ROOT = '/staticfiles/'
#STATIC_ROOT = os.path.join(BASE_DIR, "static/")
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
当我尝试使用上述配置加载图像时。我无法得到答复。错误抛出
"GET http://127.0.0.1:8000/static/images/abc.png 404 (Not Found)"
谢谢!
答案 0 :(得分:0)
我忘了在installed_apps中添加项目名称
当我添加它有效!