【问题标题】:I have tried many solutions but image is not showing when I run server. ;( on django我尝试了很多解决方案,但运行服务器时没有显示图像。 ;(在django上
【发布时间】:2021-05-23 09:48:43
【问题描述】:
{% 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 %}

我收到了这个错误:

[20/Feb/2021 21:49:31] "GET /project/1 HTTP/1.1" 200 1427
Not Found: /project/static/img/1-webgrow.jpg

静态文件夹在项目目录中。

这是视图函数:

def details(request, pk):
    project = Project.objects.get(pk=pk)
    context = {
        'project': project
    }
    return render(request, 'details.html', context)

请帮忙

【问题讨论】:

    标签: python django http-status-code-404 web-deployment


    【解决方案1】:

    您忘记在代码中使用 .url 应该是这样的

    <img class="img-fluid" src="{{project.image.url}}">
    

    而且,模型的图像不存储在静态文件夹中,它们在媒体根目录中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-22
      • 1970-01-01
      • 2019-09-21
      • 2012-06-06
      • 2019-09-28
      • 1970-01-01
      • 2014-08-07
      • 2020-01-07
      相关资源
      最近更新 更多