博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Flask常见错误与解决方法
阅读量:2784 次
发布时间:2019-05-13

本文共 1684 字,大约阅读时间需要 5 分钟。

1.ValueError: urls must start with a leading slash

这个错误原因可能发生在所有路由相关地方,少加了一个'/'造成的。

 

2.ImportError: cannot import name 'db'

 

这个错误原因是产生了循环导入问题,修改import的位置即可

 

3.AssertionError: View function mapping is overwriting an existing endpoint function: manager.check_permission

 

这个错误原因是自定义的装饰器中没有使用functools模块下的wraps(func)修饰wrapper (func)

 

4.socket.gaierror: [Errno -2] Name or service not known

 

这个错误原因是当发送邮件等事务发生时,虚拟机没联网

 

5.The method is not allowed for the requested URL.

 

这个错误原因是路由书写时候,前一个路由没有写methods=['POST','GET']

 

6.AttributeError: 'SQLAlchemy' object has no attribute 'commit'

 

这个错误原因是db.session.commit(),可能忘记写session

 

7.RuntimeError: No application found. Either work inside a view function or push an application context.

 

这个错误原因是应该写进视图模块中的代码约束,写到了表单模块中

 

8.TypeError: redirect() got an unexpected keyword argument 'id'

 

这个错误原因可能不仅仅是重定向传错参数,还有可能只写了redirect,忘记写url_for

 

9.ERROR [root] Error: Can't locate revision identified by '8a92edbd0e8e'

 

这个问题是数据库中表alembic_version版本过低,直接删除

 

  1. 修改字段长度,显示ERROR [root] Error: Target database is not up to date.

 

(agent_env) [root@localhost testtool]# python manage.py db heads

58afe69195e2 (head)

(agent_env) [root@localhost testtool]# python manage.py db current

INFO  [alembic.runtime.migration] Context impl MySQLImpl.

INFO  [alembic.runtime.migration] Will assume non-transactional DDL.

627e0ff03ba2

(agent_env) [root@localhost testtool]# python manage.py db stamp heads

INFO  [alembic.runtime.migration] Context impl MySQLImpl.

INFO  [alembic.runtime.migration] Will assume non-transactional DDL.

INFO  [alembic.runtime.migration] Running stamp_revision 627e0ff03ba2 -> 58afe69195e2

(agent_env) [root@localhost testtool]# python manage.py db migrate

 

 

alembic常用命令和经典错误解决办法

 

转载地址:http://etfld.baihongyu.com/

你可能感兴趣的文章
ES6-Object的变化
查看>>
ES6-Symbol类型
查看>>
ES6-Iterator与for..of..遍历
查看>>
ES6-Generator与异步操作
查看>>
ES6-Promise
查看>>
React-基于React & Reflux 的评论框组件 (ES6)
查看>>
HTML5-postMessage实现跨域
查看>>
HTML5-Web Workers实现多线程
查看>>
JavaScript-函数柯里化
查看>>
Nodejs-Express, Koa, Hapi三个框架应如何选择
查看>>
JavaScript-装饰器函数(Decorator)
查看>>
JavaScript-观察者模式(publish/subscribe)
查看>>
HTTP-URL中查询字符串格式化
查看>>
HTTP-URL编码函数
查看>>
JavaScript-父子dom同时绑定两个点击事件,一个用捕获,一个用冒泡时执行顺序
查看>>
JavaScript-可维护代码编写,函数式编程与纯函数
查看>>
移动端开发-viewport实现响应式设计
查看>>
移动端开发-touch事件及其相关属性
查看>>
JavaScript-性能优化,函数节流(throttle)与函数去抖(debounce)
查看>>
HTML5-Service Worker实现离线页面访问
查看>>