@1kbfree
2018-05-16T23:11:39.000000Z
字数 487
阅读 1144
flask
静态文件是存放
css
、js
、img
等文件的,一般是在strtic
创建目录:
from flask import Flask,render_template,url_for
app = Flask(__name__)
@app.route('/')
def index():
context = {}
css_url = url_for('static', filename='index.css') #获取到static目录下的index.css文件的地址,赋值到css_url变量里
js_url = url_for('static', filename='index.js') #同上
context['css_url'] = css_url
context['js_url'] = js_url
context['title'] = '首页' #标题
return render_template('index.html',**context)
if __name__ == '__main__':
app.run(debug=True,host='127.0.0.1',port=80)