文章目录
一、vscode不安装插件直接设置html、css、js补全
找到settings.json文件添加如下代码:
"editor.suggest.snippetsPreventQuickSuggestions": false,
"html.autoClosingTags": true,
"files.associations": {
"*.js": "html",
"*.vue":"html",
"*.html":"html"
},
二、flask使用
1、在浏览器打开错误
http://localhost:5000
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
解决:
是不是没有建立templates文件夹。这是flask模板文件的默认文件夹,必须要有,要把这些html文件放在里面,当然文件夹的名字可以通过修改代码自己设置。可以参考这个解答
2、redirect(url_for)和render_template区别
ps:这个坑我找了好久怎么解决,都要吐了,详细的知识点之后再去补充,目前这里只记录我成功执行代码的解决方法。 原理见博客修改视图函数名
- redirect(url_for) 会重定向url,返回码是302
url_for()里面是一个函数,所以要写一个函数是渲染url路径的 - render_template()是直接渲染html页面的,返回码是200
3、关于HTML注释
在jinja2模板中一定不要写这样的注释
<!-- in tag {% %} dosen't use tag {{ }}, so just delete {{}} -->
jinja2的注释是{# #}
我还以为写在html中就是用html的注释呢,折腾了我两个小时,哭泣。
pymysql是python的mysql数据库驱动,flask下的sqlachemy是一个数据库框架