美文网首页
Flask 教程填坑记

Flask 教程填坑记

作者: _gitignore | 来源:发表于2019-07-24 01:20 被阅读0次

按照Flask Tutorial挖坑遭遇

RuntimeError: Working outside of application context.

求解半天,也没看懂。因为刚入门,看资料也看不懂。Stackoverflow上倒是有一个类似的答案,可是我没看懂。。

下载了官方文档的代码,运行,同样 的报错。

没办法,硬着头皮看下去,终于在若干个页面之后找到了这个解决方案:

Manually Push a Context

If you try to access current_app, or anything that uses it, outside an application context, you’ll get this error message:

RuntimeError: Working outside of application context.

This typically means that you attempted to use functionality that
needed to interface with the current application object in some way.
To solve this, set up an application context with app.app_context().

If you see that error while configuring your application, such as when initializing an extension, you can push a context manually since you have direct access to the app. Use app_context() in a with block, and everything that runs in the block will have access to current_app.

def create_app():
    app = Flask(__name__)

    with app.app_context():
        init_db()

    return app

If you see that error somewhere else in your code not related to configuring the application, it most likely indicates that you should move that code into a view function or CLI command.

顺便发一张爬坑成功的截图:


image.png

相关文章

  • Flask 教程填坑记

    按照Flask Tutorial挖坑遭遇 求解半天,也没看懂。因为刚入门,看资料也看不懂。Stackoverflo...

  • UiAutomator2.0升级填坑记

    UiAutomator2.0升级填坑记

  • 填坑记

    后台像前台传值时遇到一个问题: 坑1 使用console.log打印后台传来的json值时只显示[object O...

  • 填坑记

    btng_upload_IDcard id 如果控件不冲突,就是控件所在的layout文件冲突了,多module下...

  • flask高级编程_鱼书项目_填坑记

    详细过程可以去我的个人博客上查看,另有flask构建可扩展restful-api过程.个人博客,gitbook 下...

  • 记安装pyspectator填坑记

    原文链接:一只电工的博客 记安装pyspectator填坑记: Environment INFO: windows...

  • Laravel入门

    参考资料 教程 文档 填坑 运行找不到vendor文件夹?composer update --no-scripts...

  • activeMQ 填坑记

    前言 MQ是现在大型系统架构中必不可少的一个重要中间件,之前有偏文章《MQ(消息队列)常见的应用场景解析》介绍过M...

  • 填坑记(UI)

    1. tableView刷新闪屏 场景:类似于聊天界面,快速多次发送消息,刷新界面并且滚动到最后一条问题:scro...

  • 填坑记(逻辑)

    1. 在https页面去请求http的资源 问题:https页面内的资源加载不出来,为空白原因:浏览器有安全设置,...

网友评论

      本文标题:Flask 教程填坑记

      本文链接:https://www.haomeiwen.com/subject/zzzzlctx.html