django - django css 不会从索引 url 而不是任何其他 url 加载
问题描述
为什么css从索引url而不是任何其他url加载?
网址:
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)
视图.py:
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)
产品.html:
{%加载静态%}
<meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <title>Nakahaty</title> <meta name="keywords" content="HTML5 Template"> <meta name="description" content="Molla - Bootstrap eCommerce Template"> <meta name="author" content="p-themes"> <!-- Favicon --> <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"
颜色="#666666">
编辑:当我从索引 URL 加载相同的 HTML 文件时它可以工作,否则它不会加载 css 文件
ps:不使用表格
{% static ..%}
解决方案
您需要像这样定义静态网址。
{% load static %}
<link rel="manifest" href=" {% static 'static/assets/images/icons/site.html' %}">
推荐阅读
- c# - 如何在 Xamarin.Forms 中使用 ContentProperty?
- sql - 将连接中的逗号分隔值插入特定列
- javascript - 对象数组中的特定数据
- wordpress - woocommerce REST API 请求购买单品
- sympy - 为什么 sympy count_ops() 因集成而失败?
- php - 仅使用 PHP 列出来自 FTP 服务器的文件夹
- python-3.x - TensorFlow 中更快的 K-Means 聚类
- sql - SQL 查询未返回预期结果
- php - 未定义函数 mssql_connect() Codeigniter 3.0 + Azure 数据库 + 000webhost + PHP 5.6
- ruby-on-rails - 如何在 Jbuilder 中合并 JSON 对象