我尝试了很多解决方案,但是当我 运行 服务器时图像没有显示。 ;( 在 Django 上
I have tried many solutions but image is not showing when I run server. ;( on django
{% extends "base.html" %}
{% load static %}
{% block content %}
<h1>{{ project.title }}</h1>
<div class="row">
<div class="col-md-8">
**<img class="img-fluid" src="{{project.image}}">**
</div>
<div class="col-md-4">
<h5>About the project:</h5>
<p>{{ project.description }}</p>
<br>
<h5>Technology used:</h5>
<p>{{ project.technology_used }}</p>
</div>
</div>
{% endblock %}
I got this error:
[20/Feb/2021 21:49:31] "GET /project/1 HTTP/1.1" 200 1427
Not Found: /project/static/img/1-webgrow.jpg
静态文件夹在项目目录中。
This is the view function:
def details(request, pk):
project = Project.objects.get(pk=pk)
context = {
'project': project
}
return render(request, 'details.html', context)
请帮忙
您忘记在代码中使用 .url
应该是这样
<img class="img-fluid" src="{{project.image.url}}">
此外,模型的图像不存储在 statics 文件夹中,它们在媒体根目录中
{% extends "base.html" %}
{% load static %}
{% block content %}
<h1>{{ project.title }}</h1>
<div class="row">
<div class="col-md-8">
**<img class="img-fluid" src="{{project.image}}">**
</div>
<div class="col-md-4">
<h5>About the project:</h5>
<p>{{ project.description }}</p>
<br>
<h5>Technology used:</h5>
<p>{{ project.technology_used }}</p>
</div>
</div>
{% endblock %}
I got this error:
[20/Feb/2021 21:49:31] "GET /project/1 HTTP/1.1" 200 1427
Not Found: /project/static/img/1-webgrow.jpg
静态文件夹在项目目录中。
This is the view function:
def details(request, pk):
project = Project.objects.get(pk=pk)
context = {
'project': project
}
return render(request, 'details.html', context)
请帮忙
您忘记在代码中使用 .url 应该是这样
<img class="img-fluid" src="{{project.image.url}}">
此外,模型的图像不存储在 statics 文件夹中,它们在媒体根目录中