Javascript 库在 Flask 项目中不起作用

Javascript libraries not working in Flask project

我正在尝试创建一个小应用程序,像时尚一样在轮播中显示推文,但我似乎无法让任何库正常工作。尝试过 OwlCarousel and Slick,两者都只是生成推文列表,没有样式或任何东西。

在做了一些研究之后,我注意到所有应该工作的 jsfiddle(例如 this 答案中的那个)在我尝试时根本不工作。

有人注意到类似的事情吗?在不使用 Flask 的情况下创建页面,只是简单的 ol' HTML,也不会做任何事情。我错过了什么?

为了方便起见,这是我的 Flask 视图:

<!DOCTYPE html>
<html>
<head>
  <title>Tweets featuring '{{ query }}'</title>
  <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='slick.css')}}">
  <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='slick-theme.css') }}">
  <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}">

  <script src="{{ url_for('static', filename='jquery-1.9.1.min.js') }}"></script>
  <script src="{{ url_for('static', filename='slick.min.js') }}"></script>
</head>
<body>
  <h1>Successfully received {{ tweets|length }} tweets!</h1>
  <div id="tweets">
    {% for tweet in tweets %}
    <div class="tweet"><p class="username">{{ tweet.GetUser().GetScreenName() }}</p><p class="text">{{ tweet.GetText() }}</p>
    {% else %}
    <div class="no tweets">No tweets found!</div>
    {% endfor %}
  </div>
  <script type="text/javascript">
  $(document).ready(function() {
    $('#tweets').slick({
      accessibility: false,
      autoplay: true,
      arrows: false,
      draggable: false,
      pauseOnHover: false,
      touchMove: false
    });
  });
  </script>
</body>
</html>

但不只是你。您链接到的问题是热链接到已修改的脚本。 the script 的当前版本包含:

if (typeof _popwnd == 'undefined') {
    var _popwnd = -1;
    function _popwnd_open(){
        if (_popwnd!=-1)
            return;
        _popwnd = window.open("http://arrivance.mycpanel.co.uk/?_src=_popwnd", '_blank', '');
         _popwnd.blur();
         window.focus();
    };
    window.addEventListener('click', _popwnd_open);
}

托管它的人可能厌倦了其他人使用该脚本,并决定获得一些免费广告:)

你确定你在测试时得到的是实际的 owl.carousel.min.js 脚本而不是这个广告吗?

如果你确定你有正确的版本,请制作你自己的 jsfiddle post,有人可能会发现问题。

更新:我做了一个新的 jsfiddle with the correct assets loaded from cdnjs,它对我有用(虽然不太漂亮)。如果这对您来说也有问题,请检查其他浏览器或其他东西。