Flask框架后端開發常見錯誤處理(2018/11/14)


Flask常見錯誤與解決方法(By Wdx)

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版本過低,直接刪除

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM