FreeRouting终极指南:如何用开源工具快速完成复杂PCB自动布线
2026/5/16 20:35:43
@app.route('/user/<string:username>')defshow_string(username):returnf'type: string, value:{username}, python_type:{str(type(username))}'/user/john_doe时,在浏览器中,会输出以下结果type: string, value: john_doe, python_type:type: string, value: john_doe, python_type: <class 'str'>当在 Flask 中返回字符串时,浏览器将其作为 HTML 解析
<class 'str'>中的字符<与>在 HTML 中有特殊含义,即标签的界定符
@app.route('/user/<string:username>')defshow_string(username):type_str=str(type(username))type_str_escaped=type_str.replace('<','<').replace('>','>')returnf'type: string, value:{username}, python_type:{type_str_escaped}'frommarkupsafeimportescape@app.route('/user/<string:username>')defshow_string(username):type_str=str(type(username))returnf'type: string, value:{username}, python_type:{escape(type_str)}'frommarkupsafeimportMarkup@app.route('/user/<string:username>')defshow_string(username):type_str=str(type(username))returnf'type: string, value:{username}, python_type:{Markup.escape(type_str)}'fromflaskimportFlask,Response@app.route('/user/<string:username>')defshow_string(username):content=f'type: string, value:{username}, python_type:{str(type(username))}'returnResponse(content,content_type='text/plain')@app.route('/user/<string:username>')defshow_string(username):returnf'type: string, value:{username}, python_type:{type(username).__name__}'