首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >django css不从索引url加载,也不从任何其他url加载

django css不从索引url加载,也不从任何其他url加载
EN

Stack Overflow用户
提问于 2020-07-19 10:35:17
回答 3查看 155关注 0票数 0

为什么css从索引url而不是任何其他url加载?

网址:

代码语言:javascript
复制
    urlpatterns = [
    path("", views.index, name="index"),
    path("product/<slug>", views.product, name="product"),] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
#+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

views.py:

代码语言:javascript
复制
def index(request):
return render(request, "product.html")

def product(request, slug):
    product = Product.objects.get(slug='iphone-11')
    print(product.image1.url)
    context = {'product': product}
    return render(request, "product.html", context)

product.html:

{%加载静态%}

编辑:当我从索引URL加载相同的HTML文件时,它会工作,否则它不会加载css文件

ps:不用表格

代码语言:javascript
复制
{% static ..%}
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2020-07-19 10:52:46

如果使用Django,请使用Django:

代码语言:javascript
复制
<link rel="apple-touch-icon" sizes="180x180" href="{% static 'assets/images/icons/apple-touch-icon.png' %}">
<link rel="icon" type="image/png" sizes="32x32" href="{% static 'assets/images/icons/favicon-32x32.png' %}">
<link rel="icon" type="image/png" sizes="16x16" href="{% static 'assets/images/icons/favicon-16x16.png' %}">
<link rel="manifest" href="{% static 'assets/images/icons/site.html' %}">
<link rel="mask-icon" href="{% static 'assets/images/icons/safari-pinned-tab.svg' %}">
<link rel="stylesheet" href="{% static 'your css folder/ your css file name' %}

阅读关于的文章

票数 1
EN

Stack Overflow用户

发布于 2020-07-19 10:42:50

您需要像这样定义静态url。

代码语言:javascript
复制
{% load static %}
<link rel="manifest" href=" {% static 'static/assets/images/icons/site.html' %}">
票数 1
EN

Stack Overflow用户

发布于 2020-07-19 10:43:42

指向静态文件的路径不正确。看起来应该是:

代码语言:javascript
复制
{% load static %}
<link rel="apple-touch-icon" sizes="180x180" href="{% static 'assets/images/icons/apple-touch-icon.png' %}">```
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62979139

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档