外部 css 文件在 Flask 框架中不起作用 [英] external css file doesn't work in Flask framework

查看:32
本文介绍了外部 css 文件在 Flask 框架中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的 html 文件中使用外部 css 文件.起初我使用引导框架,它运行良好.但是,当我尝试通过添加自定义 css 文件来自定义网页时,它根本不起作用!这是我的代码:

I'm trying to use an external css file in my html file. At first I used bootstrap framework and it works well. However, when I tried to customize the web page by adding a customized css file, it doesn't work at all! Here is my code:

    <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.min.css">
<script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://apps.bdimg.com/libs/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="custom.css" type="text/css">

custom.css:

custom.css:

body{
background-color: #9acfea;}

这里我只想改变背景颜色.

Here I just want to change the background color.

'custom.css' 与 HTML 文件在同一路径下.另外,我尝试只应用custom.css",所以我创建了一个新的 HTML 文件:

'custom.css' is under the same path with the HTML file. Also, I've tried to only apply 'custom.css', so I create a new HTML file:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="custom.css" type="text/css"/>
</head>
<body>
    hello
</body>
</html>

它也不起作用.我糊涂了.为什么 bootstrap css 文件可以完美运行,而自定义文件却不能?顺便说一句,我使用的是 Flask 框架,但我认为这并不重要.任何建议将不胜感激!

It doesn't work either. I'm confused. Why the bootstrap css file works perfect but the customized file doesn't? By the way, I'm using the Flask framework, but I don't think it matters. Any suggestions would be appreciate!

推荐答案

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

这篇关于外部 css 文件在 Flask 框架中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆