“2018年7月”存档文章有45

flask 多个form.csrf_token如何处理

最近有一个页面有多个,但是每次只提交一个表单。使用{{ form.csrf_token }}保护表单,避免跨域请求。但是当表单有多个{{ form.csrf_token }}的时候,id都是一样的,会出现如下提示:[DOM] Found 2 elements with non-unique id #csrf_token: (More info: https://goo.gl/9p2vKq)看看生成...

nginx 配置不当导致url_for('')出问题

最近一边写程序,一边发布,但是有一个地方始终有问题,当点击登陆的时候,用户名和密码都正确,跳转到管理界面,但是url始终错误:本来应该是http://pdflibr.com/manage/index,但是却变成了:http://pdflibr.com%2Cpdflibr.com/manage/index。后台代码如下所示:@auth.route('/login', methods=['GET', ...

flask 更新数据库失败

在使用SQLALchemy更新数据的时候,一直不成功。数据更新的方式采用ajax,具体代码如下:$(function () { $('#user_profile').click(function (event) { event.preventDefault(); //prevent the actual form post user_profile(...

405 (METHOD NOT ALLOWED)

在使用Flask的时候,报如下错误:405 (METHOD NOT ALLOWED)原因:是因为视图文件没有写清楚提交方式。错误代码如下:@manage.route('/user/') @login_required def user(username): # 判断当前登陆用户名 get_current_username = current_user.username ...

jinja2.exceptions.UndefinedError: there is no parent block called 'top_menu'.

使用Flask jinja2,报如下错误:jinja2.exceptions.UndefinedError: there is no parent block called 'top_menu'.原因:父模板没有top_menu模块,但是在这里代码是这样写的:<!-- BEGIN TOP NAVIGATION MENU -->{% block top_menu %} {{ super() }...

Block names in Jinja have to be valid Python identifiers and may not contain hyphens, use an underscore instead

最近在使用python的时候,报如下错误:jinja2.exceptions.TemplateSyntaxError: Block names in Jinja have to be valid Python identifiers and may not contain hyphens, use an underscore instead.出现这个问题的原因:jinja2.exceptions....

mysql查看和修改数据库表字段编码格式及添加删除外键操作

1.查看数据库编码格式mysql> show variables like 'character_set_database'; 2.查看数据表的编码格式mysql> show create table <表名>; 3.创建数据库时指定数据库的字符集mysql>create database <数据库名> character set utf8;4.创建数据表时指定数据表的编码格式create tab...

1366, "Incorrect string value: '\\xE9\\xBB\\x84\\xE5\\x85\\xB5' for column 'fullname' at row 1"

最近使用SQLALchemy的时候,出现了如下错误:sqlalchemy.exc.InvalidRequestError: This Session's transaction has been rolled back due to a previous exception during flush. To begin a new transaction with this Session, fi...