【问题标题】:Error404 while loading CSS in HTML script in Python在 Python 中的 HTML 脚本中加载 CSS 时出现 Error404
【发布时间】:2020-08-25 18:00:03
【问题描述】:

查看附件代码:我收到 404 并且有一个指向我的目录的链接。

<!DOCTYPE html>
<html>
  <head>
    <title>Flask App</title>
    <link rel="stylesheet" href="{{url_for('static',filename='css/main.css')}}"
  </head>
  <body>
    

你知道有什么问题吗?在此处查看目录: 1:https://i.stack.imgur.com/g3Gia.jpg

【问题讨论】:

    标签: python html css flask


    【解决方案1】:

    我认为你应该将静态文件夹移动到烧瓶文件夹

    【讨论】:

      【解决方案2】:

      这样做:

      <head>
          <title>Flask App</title>
          <link rel="stylesheet" href="/static//css/main.css"
        </head>
      

      在 Flask 中编辑这一行:

      这个:app=Flask (__name__)

      对此:app=Flask (__name__,static_url_path="/static")

      【讨论】:

      • 感谢您的回答,但仍然收到 404!
      • GET /static/css/main.css HTTP/1.1" 404. 我应该链接到完整路径吗?
      • 您的 .css 文件路径必须是 .py 文件中的这样:static/css/main.css。编辑后使用 ctrl+F5 清除缓存
      • 谢谢Revisto,会试一试,然后回来找你!
      猜你喜欢
      • 2011-09-06
      • 1970-01-01
      • 2018-11-15
      • 1970-01-01
      • 1970-01-01
      • 2020-07-20
      • 2014-10-16
      • 2016-11-07
      • 1970-01-01
      相关资源
      最近更新 更多