Flask常见错误与解决方法
1.ValueError: urls must start with a leading slash
這個(gè)錯(cuò)誤原因可能發(fā)生在所有路由相關(guān)地方,少加了一個(gè)’/'造成的。
2.ImportError: cannot import name ‘db’
這個(gè)錯(cuò)誤原因是產(chǎn)生了循環(huán)導(dǎo)入問(wèn)題,修改import的位置即可
3.AssertionError: View function mapping is overwriting an existing endpoint function: manager.check_permission
這個(gè)錯(cuò)誤原因是自定義的裝飾器中沒(méi)有使用functools模塊下的wraps(func)修飾wrapper (func)
4.socket.gaierror: [Errno -2] Name or service not known
這個(gè)錯(cuò)誤原因是當(dāng)發(fā)送郵件等事務(wù)發(fā)生時(shí),虛擬機(jī)沒(méi)聯(lián)網(wǎng)
5.The method is not allowed for the requested URL.
這個(gè)錯(cuò)誤原因是路由書(shū)寫(xiě)時(shí)候,前一個(gè)路由沒(méi)有寫(xiě)methods=[‘POST’,‘GET’]
6.AttributeError: ‘SQLAlchemy’ object has no attribute ‘commit’
這個(gè)錯(cuò)誤原因是db.session.commit(),可能忘記寫(xiě)session
7.RuntimeError: No application found. Either work inside a view function or push an application context.
這個(gè)錯(cuò)誤原因是應(yīng)該寫(xiě)進(jìn)視圖模塊中的代碼約束,寫(xiě)到了表單模塊中
8.TypeError: redirect() got an unexpected keyword argument ‘id’
這個(gè)錯(cuò)誤原因可能不僅僅是重定向傳錯(cuò)參數(shù),還有可能只寫(xiě)了redirect,忘記寫(xiě)url_for
9.ERROR [root] Error: Can’t locate revision identified by ‘8a92edbd0e8e’
這個(gè)問(wèn)題是數(shù)據(jù)庫(kù)中表alembic_version版本過(guò)低,直接刪除
總結(jié)
以上是生活随笔為你收集整理的Flask常见错误与解决方法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Flask的csrf_token校验
- 下一篇: Flask 报错 RuntimeErro