无法显示静态图像和CSS文件(Not able to display static images and css files)

编程入门 行业动态 更新时间:2024-10-11 11:21:02
无法显示静态图像和CSS文件(Not able to display static images and css files)

我想显示静态图像和CSS文件

settings.py

STATIC_PATH = os.path.join(BASE_DIR,'static') STATIC_URL = '/static/' STATICFILES_DIRS = ( BASE_DIR +"/articles/static",) STATIC_ROOT = os.path.join(BASE_DIR,"static",)

在模板中我正在尝试显示img文件夹中的图像

article.html

{% load staticfiles %} <img src = "{% static '/img/default-by.gif' %}" alt = "left slide"/>

文件夹结构

根据django docs我尝试访问静态图像的文件夹结构https://docs.djangoproject.com/en/1.9/intro/tutorial06/文件夹结构

NewsArticles -->articles --> static -->articles -->img -->default-by.gif db.sqlite3 manage.py media NewsArticles README.md static templates

我正在使用firebug检查其显示的图像位置,如提到的http://127.0.0.1:8000/static/img/default-by.gif

I want to display static images and CSS file

settings.py

STATIC_PATH = os.path.join(BASE_DIR,'static') STATIC_URL = '/static/' STATICFILES_DIRS = ( BASE_DIR +"/articles/static",) STATIC_ROOT = os.path.join(BASE_DIR,"static",)

In Template I am trying display the images from img folder

article.html

{% load staticfiles %} <img src = "{% static '/img/default-by.gif' %}" alt = "left slide"/>

Folder Structure

The folder structure where I have tried to access static images according to the django docs https://docs.djangoproject.com/en/1.9/intro/tutorial06/ Folder Structure

NewsArticles -->articles --> static -->articles -->img -->default-by.gif db.sqlite3 manage.py media NewsArticles README.md static templates

I am using firebug to check the image location its showing as mentioned http://127.0.0.1:8000/static/img/default-by.gif

最满意答案

你为你的形象提供了错误的道路。 它应该是这样的

{% load staticfiles %} <img src = "{% static 'articles/img/default-by.gif' %}" alt = "left slide"/>

希望这会奏效。

You are giving wrong path for your image. It should be like this

{% load staticfiles %} <img src = "{% static 'articles/img/default-by.gif' %}" alt = "left slide"/>

Hope this will works.

更多推荐

static,img,图像,文件夹,电脑培训,计算机培训,IT培训"/> <meta name="description

本文发布于:2023-04-29 01:36:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1334450.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:静态   图像   文件   CSS   display

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!