【问题标题】:Javascript not loading on website with python [duplicate]Javascript没有在使用python的网站上加载[重复]
【发布时间】:2015-12-03 23:43:26
【问题描述】:

我正在使用带有烧瓶框架的 python 制作一个网站,但我似乎无法让我的 javascript 页面像处理外部 css 文件一样处理 html。我不确定错误发生在哪里,无论是在我链接 javascript 的 html 头(下)中,还是在 javascript 文件中或在 python 文件中。

<head>
 <meta charset="UTF-8">
 <link rel = "stylesheet" type="text/css" href="../static/HotelStyle.css">
 <title> Hotel </title> 
 <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
 <script src="../static/hotel.js"></script>
 <script type="text/javascript"></script>
</head>

【问题讨论】:

标签: javascript python html flask


【解决方案1】:

如果您为 flask 正确定义了静态目录,您应该能够通过使用url_for 为您的静态文件使用正确的 url。例如在这种情况下它将是:

<head>
<meta charset="UTF-8">
<link rel = "stylesheet" type="text/css" href="{{ url_for('static', filename='HotelStyle.css') }}">
<title> Hotel </title> 
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="{{ url_for('static', filename='hotel.js') }}"></script>
<script type="text/javascript"></script>
</head>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-30
    • 1970-01-01
    • 2012-06-02
    • 2016-12-06
    相关资源
    最近更新 更多