python - 光滑的旋转木马在 Flask 中不起作用

标签 python css flask

<分区>

我在桌面上打开了 Slick-Carrousel 包。当我在我的桌面上运行这个包时,它工作了。但是当我将 Slick 复制并粘贴到我的 Flask 模板目录并修改我的 Controller 以加载索引文件时,所有链接都被破坏了。我也提取到程序的根目录,但链接仍然断开。

我可以通过使用 jsdeliver.net 修复 CSS 链接获得有限的功能,但我不知道如何链接字体类别中的所有不同文件类型,这些文件类型不会在控制台中显示为 404。

文件可以在这里找到: http://www.jsdelivr.com/projects/jquery.slick

具体来说,如何链接gif、eot、svg、ttf和woff文件?

编辑:这是我的 HTML

<!DOCTYPE html>
<html>
<head>
  <title>Slick Playground</title>
  <meta charset="UTF-8">
  <link rel="stylesheet" type="text/css" href="./slick/slick.css">
  <link rel="stylesheet" type="text/css" href="./slick/slick-theme.css">
  <style type="text/css">
    html, body {
      margin: 0;
      padding: 0;
    }

    * {
      box-sizing: border-box;
    }

    .slider {
        width: 50%;
        margin: 100px auto;
    }

    .slick-slide {
      margin: 0px 20px;
    }

    .slick-slide img {
      width: 100%;
    }

    .slick-prev:before,
    .slick-next:before {
        color: black;
    }
  </style>
</head>
<body>

  <section class="regular slider">
    <div>
      <img src="http://placehold.it/350x300?text=1">
    </div>
    <div>
      <img src="http://placehold.it/350x300?text=2">
    </div>
    <div>
      <img src="http://placehold.it/350x300?text=3">
    </div>
    <div>
      <img src="http://placehold.it/350x300?text=4">
    </div>
    <div>
      <img src="http://placehold.it/350x300?text=5">
    </div>
    <div>
      <img src="http://placehold.it/350x300?text=6">
    </div>
  </section>

  <section class="center slider">
    <div>
      <img src="http://placehold.it/350x300?text=1">
    </div>
    <div>
      <img src="http://placehold.it/350x300?text=2">
    </div>
    <div>
      <img src="http://placehold.it/350x300?text=3">
    </div>
    <div>
      <img src="http://placehold.it/350x300?text=4">
    </div>
    <div>
      <img src="http://placehold.it/350x300?text=5">
    </div>
    <div>
      <img src="http://placehold.it/350x300?text=6">
    </div>
    <div>
      <img src="http://placehold.it/350x300?text=7">
    </div>
    <div>
      <img src="http://placehold.it/350x300?text=8">
    </div>
    <div>
      <img src="http://placehold.it/350x300?text=9">
    </div>
  </section>

  <section class="variable slider">
    <div>
      <img src="http://placehold.it/350x300?text=1">
    </div>
    <div>
      <img src="http://placehold.it/200x300?text=2">
    </div>
    <div>
      <img src="http://placehold.it/100x300?text=3">
    </div>
    <div>
      <img src="http://placehold.it/200x300?text=4">
    </div>
    <div>
      <img src="http://placehold.it/350x300?text=5">
    </div>
    <div>
      <img src="http://placehold.it/300x300?text=6">
    </div>
  </section>

  <script src="https://code.jquery.com/jquery-2.2.0.min.js" type="text/javascript"></script>
  <script src="./slick/slick.js" type="text/javascript" charset="utf-8"></script>
  <script type="text/javascript">
    $(document).on('ready', function() {
      $(".regular").slick({
        dots: true,
        infinite: true,
        slidesToShow: 3,
        slidesToScroll: 3
      });
      $(".center").slick({
        dots: true,
        infinite: true,
        centerMode: true,
        slidesToShow: 3,
        slidesToScroll: 3
      });
      $(".variable").slick({
        dots: true,
        infinite: true,
        variableWidth: true
      });
    });
  </script>

</body>
</html>

这是我的文件结构的截图:

enter image description here

编辑:这篇文章被标记为这个问题的重复:Link to Flask static files with url_for

但我有一个不同的问题。我没有尝试使用 URL-for 链接单个文件。我正在尝试链接整个目录,以便 javascript 可以找到它需要的所有文件。

最佳答案

问题是我需要写:

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

添加静态目录。 Flask 文件需要放在静态目录中,我需要在链接中反射(reflect)此更改。

关于python - 光滑的旋转木马在 Flask 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43927720/

上一篇:html - 为我自己的样式重用 Bootstrap 类名?

下一篇:javascript - 如何让我的 iframe 响应所有设备?

相关文章:

一行中的 Python 素数生成器

css - anchor 标签上的边框底部,适用于多行和内联 block / block 显示

html - flexbox 容器的绝对宽度

javascript - 尝试在鼠标进入时随机化 div 颜色

python - 有没有办法在 Flask WTForms 中创建数据列表字段?

python - 使用 (apitoken/apikey) 自动上传 bugsense proguard 映射文件

python - 在 Python 中将答案四舍五入到小数点后两位

python - Flask-WTF - 无法测试表单提交

python - "from django.views.generic import list_detail"的当前 Django 是什么?

python - 比较元组值