烧瓶应用程序 - 如何将JavaScript文件链接到网站 [英] Flask Application - How to link a javascript file to website
问题描述
#!flask / bin / python
from应用程序导入应用程序
app.run(debug = True)
下面的代码给出了一个404错误:
错误消息:
我的文件结构如下所示:
任何提示去错了吗?
是的,幸运的是我目前正在开发一个烧瓶应用程序。 b
您目前缺少静态文件夹,默认情况下,文件夹结构如下所示:
| FlaskApp
---- | FlaskApp
- ------- |模板
- html文件在这里
-------- | static
- css和javascript文件在这里
Flask将查看模板和静态两个重要的默认文件夹。
一旦你得到了这个排序,你可以使用它来从你的html页面链接到你的javascript文件:
< script src ={{url_for('static',filename ='somejavascriptfile.js')}}>< / script>
希望能帮到任何问题。
<加上 - 一个很好的文章阅读,但不是超级相关,但它谈到了瓶的文件夹结构是这样的: https://www.digitalocean.com/community/tutorials/how-to-deploy-a-flask-application-on-an-ubuntu-vps
I am having some trouble getting started with using javascript files on my website (A Flask application). I start the website by running run.py which looks like this:
#!flask/bin/python
from app import app
app.run(debug=True)
In my html page I have the following code which gives a 404 error:
Error message:
My file structure looks like this:
Any hints to where I'm going wrong?
Ah yes, luckily I am currently developing a flask application at the moment.
You are currently missing the static folder which by default flask looks into, a folder structure something like this:
|FlaskApp
----|FlaskApp
--------|templates
- html files are here
--------|static
- css and javascript files are here
Two important default folders that Flask will look into templates and static. Once you got that sorted you use this to link up with your javascript files from your html page:
<script src="{{url_for('static', filename='somejavascriptfile.js')}}"></script>
Hope that helps any questions just ask.
Plus - A good article to read but not super related but it talks about the folder structure of flask is this: https://www.digitalocean.com/community/tutorials/how-to-deploy-a-flask-application-on-an-ubuntu-vps
这篇关于烧瓶应用程序 - 如何将JavaScript文件链接到网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!