from flask import Flask
from flask import request
app = Flask(__name__)
@app.route('/')
def index():
user_agent = request.headers.get('User-Agent')
return '<p>hello world</p><span>your browser agent is %s</span>' % user_agent
if __name__ == '__main__':
app.run(debug=True)
写python代码里面有时候需要写html片段, 但是pycharm似乎在python文件里面不支持使用emmet, 请问如何设置?
ringa_lee2017-04-18 09:21:05
Theoretically you should split the html into the template
If you have to write html in the py file, you can write it like this, the readability will be much better
user_agent = request.headers.get('User-Agent')
html = """
<p>hello world</p>
<span>your browser agent is {user_agent}</span>
""".format(user_agent=user_agent)
return html
大家讲道理2017-04-18 09:21:05
You should use the flask template and edit it with emmet in the template file