当前位置:网站首页>Flask (VII) - static file
Flask (VII) - static file
2022-06-11 09:27:00 【zju_ cbw】
Web Applications often need a static file , For example, support the display of web pages JavaScript File or CSS file . Usually , Can be configured by Web The server provides these services , But in the development process , These files will be provided from a static folder or module in the package , It will be in the... Of the application
/staticThe provision of .
Use special endpoints “ static state ” To generate... For static files URL.
In the following example ,index.html Medium HTML Button on the OnClick Event call hello.js As defined in javascript function , The function is in Flask Application's URL =>/ In .
from flask import Flask, render_template
app = Flask(__name__)
@app.route("/")
def index():
return render_template("index.html")
if __name__ == '__main__':
app.run(debug=True)
index.html Medium HTML The script is shown below .
<html>
<head>
<script type = "text/javascript" src = "{
{ url_for('static', filename = 'hello.js') }}" ></script>
</head>
<body>
<input type = "button" onclick = "sayHello()" value = "Say Hello" />
</body>
</html>
file : hello.js Contains sayHello() function .
function sayHello() {
alert("Hello World")
}
边栏推荐
- 远程办公最佳实践及策略
- Complexity analysis of matrix inversion operation (complexity analysis of inverse matrix)
- Openstack explanation (21) -- installation and configuration of neutron components
- Telecommuting best practices and Strategies
- Remote office related issues to be considered by enterprises
- Interview question 17.10 Main elements
- Identifier keyword literal data type base conversion character encoding variable data type explanation operator
- Tissu. JS définit dynamiquement la taille de la police
- Version mismatch between installed deeply lib and the required one by the script
- 【服装ERP】施行在项目中的重要性
猜你喜欢

Typescript high level feature 1 - merge type (&)
![Error [detectionnetwork (1)][warning]network compiled for 6 shapes, maximum available 10, compiling for 5 S](/img/54/f42146ae649836fe7070ac90f2160e.png)
Error [detectionnetwork (1)][warning]network compiled for 6 shapes, maximum available 10, compiling for 5 S

Openstack explanation (XXIII) -- other configurations, database initialization and service startup of neutron

MySQL:Got a packet bigger than ‘max_ allowed_ packet‘ bytes

Award winning survey streamnational sponsored 2022 Apache pulsar user questionnaire

Set up redis highly available cluster environment

DOS command virtual environment

Package details

Machine learning notes - spatial transformer network using tensorflow

Sed explanation of shell script (SED command, sed -e, sed s/ new / old /...)
随机推荐
【ERP体系】专业技术层面的评估,你了解多少?
机器学习笔记 - Kaggle大师Janio Martinez Bachmann的故事
Type-C Bluetooth speaker single port rechargeable OTG solution
Runtimeerror: blobreader error:the version of imported blob doesn't match graph_ transformer
Opencv CEO teaches you to use oak (V): anti deception face recognition system based on oak-d and depthai
Some learning records I=
报错Version mismatch between installed depthai lib and the required one by the scrip.
[intelligent development] scheme design and hardware development of sphygmomanometer
Award winning survey streamnational sponsored 2022 Apache pulsar user questionnaire
MSF基于SMB的信息收集
1400. construct K palindrome strings
openstack详解(二十四)——Neutron服务注册
Openstack explanation (22) -- neutron plug-in configuration
Install jupyter in the specified environment
Analysis of Kube scheduler disk scheduling source code
Type-C扩展坞自适应供电专利维权案例
1400. 构造 K 个回文字符串
Type-C docking station adaptive power supply patent protection case
Telecommuting best practices and Strategies
远程办公最佳实践及策略