RuntimeError: Working outside of request context. This typically means that you attempted to use fun
生活随笔
收集整理的這篇文章主要介紹了
RuntimeError: Working outside of request context. This typically means that you attempted to use fun
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
菜吃多了醉了
- 一、報錯情況
- 二、解決辦法
一、報錯情況
我在寫裝飾器的時候運行報錯:
RuntimeError: Working outside of request context.This typically means that you attempted to use functionality that needed an active HTTP request. Consult the documentation on testing for information about how to avoid this problem.如圖:
我也是醉了,琢磨了半天。
https://blog.csdn.net/hanhanwanghaha寶藏女孩 歡迎您的關注!
歡迎關注微信公眾號:寶藏女孩的成長日記
讓這個可愛的寶藏女孩在努力的道路上與你一起同行!
如有轉載,請注明出處(如不注明,盜者必究)
二、解決辦法
裝飾器第一個參數是原函數,如果裝飾器可以接收參數的話,那么后面可以跟別的參數,否則就只有一個參數。所以,判斷裝飾器接收的參數,如果只有一個并且第一個參數是可調用的,那么就是一個無參數的裝飾器(不需要加括號)。如果還有別的參數,就返回一個生成裝飾器的函數。
在檢查代碼的時候我就發現了一個經常犯的錯誤,就是不用加()
去掉括號就成功解決此問題
https://blog.csdn.net/hanhanwanghaha寶藏女孩 歡迎您的關注!
歡迎關注微信公眾號:寶藏女孩的成長日記
讓這個可愛的寶藏女孩在努力的道路上與你一起同行!
如有轉載,請注明出處(如不注明,盜者必究)
溫馨提示:千萬不能吃飽了就干代碼,休息會兒再敲,吃飽了會產生飯暈,你敲出來的不是代碼,而是bug!!! 哈哈哈 fighting@everyone
總結
以上是生活随笔為你收集整理的RuntimeError: Working outside of request context. This typically means that you attempted to use fun的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Python】一些容易忽略的知识点
- 下一篇: node中间件KOA函数