Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flask应用程序-如何将javascript文件链接到网站_Javascript_Html_Flask_Http Status Code 404 - Fatal编程技术网

Flask应用程序-如何将javascript文件链接到网站

Flask应用程序-如何将javascript文件链接到网站,javascript,html,flask,http-status-code-404,Javascript,Html,Flask,Http Status Code 404,在我的网站上使用javascript文件作为Flask应用程序时,我遇到了一些问题。我通过运行run.py启动网站,它如下所示: #!flask/bin/python from app import app app.run(debug=True) |FlaskApp ----|FlaskApp --------|templates - html files are here --------|static - css and javascript files a

在我的网站上使用javascript文件作为Flask应用程序时,我遇到了一些问题。我通过运行run.py启动网站,它如下所示:

#!flask/bin/python
from app import app
app.run(debug=True)
|FlaskApp
----|FlaskApp
--------|templates
        - html files are here
--------|static
        - css and javascript files are here
在我的html页面中,我有以下给出404错误的代码:

错误消息:

我的文件结构如下所示:

#!flask/bin/python
from app import app
app.run(debug=True)
|FlaskApp
----|FlaskApp
--------|templates
        - html files are here
--------|static
        - css and javascript files are here
有没有关于我哪里出错的提示?

尝试使用src=app/javascript/jquery.js


另外,我注意到您在第7行和第28行包含了两次jquery.js。

因此您的index.html位于app/templates/index.html,而jquery位于app/javascript/jquery.js,对吗

我认为你的道路是错误的。试试这个:

<script src="../javascript/jquery.js"></script>

啊,是的,幸运的是,我目前正在开发一个烧瓶应用程序

您当前缺少默认情况下flask查看的静态文件夹,文件夹结构如下:

#!flask/bin/python
from app import app
app.run(debug=True)
|FlaskApp
----|FlaskApp
--------|templates
        - html files are here
--------|static
        - css and javascript files are here
Flask将查看模板和静态的两个重要默认文件夹。 排序后,您可以使用此链接从html页面链接javascript文件:

<script src="{{url_for('static', filename='somejavascriptfile.js')}}"></script>
希望这有助于回答任何问题


另外-一篇很好的文章值得阅读,但不是超级相关的,但它讨论了flask的文件夹结构:

以下是帮助我消除flask项目中jquery部分的原因

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>

这是直接从

中找到的基本模板中获取的,您要引用的页面在哪里?我指的是索引页..我想你必须在src.app/templates/index.htmlokk.中删除/之前删除javascript..你能不能也显示控制台错误..请尝试./javascript..添加一个。在你的src之前/在你的src中。仍然有同样的问题你是说你看到404了吗http://localhost:5000/app/javascript/jquery.js ?我也有完全相同的问题,将javascript文件移动到静态工作区。但是我也想知道我是否可以把js文件放在另一个文件夹中。我试了一下,但没有成功!