简体   繁体   English

如何在桌面上的 django 的 web 页面上显示图像?

[英]How can I display an image on a web page in django that is on my desktop?

I am loading data from postgresSQL database.我正在从 postgresSQL 数据库加载数据。 This data is stored in the database by my python program.该数据由我的 python 程序存储在数据库中。 Not I am fetching data with the same functions I am using in my program.不是我正在使用我在程序中使用的相同功能获取数据。 I want to create a bar chart before displaying it on my HTML webpage in Django.我想在 Django 的 HTML 网页上显示之前创建一个条形图。 I created a chart using matplotlib and saved it on the desktop.我使用 matplotlib 创建了一个图表并将其保存在桌面上。 Now I want to fetch that image and display it.现在我想获取该图像并显示它。 I tried giving a link directly to that image but that doesn't load the picture.我尝试直接提供指向该图像的链接,但不会加载图片。

According to the Django documentation :根据Django 文档

  1. In your settings file, define STATIC_URL , for example:在您的设置文件中,定义STATIC_URL ,例如:

    STATIC_URL = '/static/'

  2. In your templates, use the static template tag to build the URL:在您的模板中,使用 static 模板标签来构建 URL:

    {% load static %} <img src="{% static "example.jpg" %}" alt="My image">

  3. Store your example.jpg image file in a folder called static in your app.将您的example.jpg图像文件存储在应用程序中名为static的文件夹中。

You can directly render the image in your python function with matplotlib.您可以使用 matplotlib 直接在 python function 中渲染图像。 After that, you will store the image to your server.之后,您将图像存储到您的服务器。 You can then can get the link and pass it to the django template.然后,您可以获得链接并将其传递给 django 模板。 Just render the img tag with the link as the src attribute.只需将带有链接的 img 标签作为 src 属性呈现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果某个进程正在我的网页上运行,如何显示? - How can I display if a process is running on my web page? 如何在台式机和移动设备上使图片中的文字动态显示 - How can i make the text in my image dynamic on desktop and mobile 如何在网页上显示随机图像2分钟,然后更改图像? - How can I display a random image on a web-page for 2 minutes, then change images? 如何使用 django 在我的 html 页面上遍历数据库中的每个项目并将它们显示在 div 中? - How can I iterate through each item in a database and display them in divs on my html page with django? 我的表格包含30个字段,如何将其显示在网页上 - My table contains 30 fields, How can I display that on a web page 我在哪里可以托管用于我的 web 页面的图像? - Where can I host an image for use in my web page? 如何将HTML文件显示为网页? - How can I display an HTML file as a web page? 如何将Django中的TemporaryUploadedFile显示为HTML图像? - How can I display a TemporaryUploadedFile from Django in HTML as an image? 如何通过SugarCRM 7 API在网页上显示图像 - How can I display images on a web page via SugarCRM 7 API 我如何在 web 页面上显示这个? 不在 console.log 上 - How can i display this on the web page? not on console.log
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM