繁体   English   中英

链接到index.html中的CSS和js文件时出错

[英]Error in linking to Css and js file in index.html

我想将我的CSS文件链接到index.html文件中。 我的项目的结构是:

MyWeb
  Views
      -> index.html
  css
      -> style.css
  js
      ->jQuery.js

我尝试了以下相对href链接,但没有任何效果。

<link href="../css/style.css" rel="stylesheet"> 
<link href="./css/style.css" rel="stylesheet">
<script src="../js/jQuery.js"></script>

这是本地托管的网站的链接: http : //127.0.0.1 : 5000/

尝试<link href="/css/style.css" rel="stylesheet">

它相对于根

在href中删除../

<link rel="stylesheet" href="css/style.css" type="text/css" />

如果您使用Flask Framework,则html文件是动态的。 尝试类似的方法:

<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">

在这里找到: Flask框架介绍

假设您的文件夹结构如下

your app templates static style.css app.py

或者你也可以这样

<link rel="stylesheet" href="/static/style.css" type="text/css" />

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM