油猴脚本开发,之如何添加html和css
warning:
这篇文章距离上次修改已过200天,其中的内容可能已经有所变动。
在使用鸡蛋脚本(Rainbow Cafe)进行开发时,您可以通过以下步骤来添加HTML和CSS:
- 在
resources/templates
目录下创建一个新的HTML文件,例如my_template.html
。 - 在
resources/static/css
目录下创建一个新的CSS文件,例如my_styles.css
。 - 在HTML文件中引入CSS文件:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Template</title>
<link rel="stylesheet" href="/css/my_styles.css">
</head>
<body>
<!-- 页面内容 -->
</body>
</html>
- 在脚本中使用
render_template
函数来渲染HTML模板,并通过send_file
发送CSS文件。
from flask import Flask, render_template, send_file
app = Flask(__name__)
@app.route('/')
def index():
return render_template('my_template.html')
@app.route('/css/<path:path>')
def send_css(path):
return send_file(f'static/css/{path}')
if __name__ == '__main__':
app.run(debug=True)
确保您的HTML模板和CSS文件的路径是正确的,并且在访问CSS文件时,路由/css/<path:path>
能正确地将请求映射到静态文件夹下的CSS文件。
评论已关闭