关于flask登录视图报错AttributeError: '_AppCtxGlobals' object has no attribute 'user'
在一个小程序中写了一个登录视图函数,代码如下:
@app.route('/login',methods = ['GET','POST'])
@oid.loginhandler
def login():
if g.user is not None and g.user.is_authenticated:
return redirect(url_for('index'))
form = LoginForm()
if form.validate_on_submit():
session['remember_me'] = form.remember_me.data
return oid.try_login(form.openid.data,ask_for=['nickname','email'])
return render_template('login.html',
title = 'Sign In',
form = form,
providers = app.config['OPENID_PROVIDERS'])
但是在登录测试的时候报错,报错信息:AttributeError: '_AppCtxGlobals' object has no attribute 'user'
经过反复检查,发现是在运行登录视图函数的时候没有确定g的位置,需要添加一个装饰函数
@app.before_request
def before_request():
g.user = current_user
记得在你的模块开头导入 current_user
希望帮助到那些被同样问题困扰的人。。。
关于flask登录视图报错AttributeError: '_AppCtxGlobals' object has no attribute 'user'的更多相关文章
- py+selenium 明明定位不到元素,但却不报错或是报错AttributeError: 'list' object has no attribute 'click'【已解决】
问题:定位不到元素,但却不报错或者出现报错AttributeError: 'list' object has no attribute 'click' 如图 或者 解决方法: 将”driver ...
- dnspython模块报错 AttributeError: 'CNAME' object has no attribute 'address'
有时候用到这个模块的时候会报错 AttributeError: 'CNAME' object has no attribute 'address' 如下所示 [root@ansible ch01]# ...
- Django2.2报错 AttributeError: 'str' object has no attribute 'decode'
准备将 Django 连接到 MySQL,在命令行输入命令 python manage.py makemigrations 后报错: AttributeError: 'str' object has ...
- python文件名不要跟模块名相同,报错AttributeError: 'module' object has no attribute 'Differ'
python中的文件都会生成pyc文件,包括模块也是这样,所以调用模块的时候,实际上会调用模块.pyc文件:在这个前提下,如果将文件名命名成跟模块名一样,在同一目录下就会生成一个跟模块名一样的pyc文 ...
- 机器学习实战:KNN代码报错“AttributeError: 'dict' object has no attribute 'iteritems'”
报错代码: sortedClassCount = sorted(classCount.iteritems(), key=operator.itemgetter(1), reverse=True) 解决 ...
- 运行pytest,报错"AttributeError: 'module' object has no attribute 'xxx'"
最近学习pytest被此问题困扰,敲脑壳,实在是不该.百度解决方法一大堆,我的问题怎么也解决不了,来看一下,我是怎么解决的,各位大佬勿喷,只是自己做笔记用,谢谢. 报错信息如下: 网上解决方法是这样的 ...
- python报错“AttributeError: 'set' object has no attribute 'items'“
作为才开始学爬虫的萌新,遇到了一个这样的错,很懵逼 后面到网络到处查看大佬的解决方法,才发现headers的请求头部信息有错误,headers是一个字典,不是字符串,所以报错了 原代码 headers ...
- [已解决]报错:报错AttributeError: 'int' object has no attribute 'upper'
原因:openpyxl版本低,需升级 pip install --upgrade openpyxl
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'module' object has no attrib ...
随机推荐
- cgg之字面值
字面值时源代码中用来描述固定值的记号,可能是整数.浮点数.字符或者字符串 2.1 整数常量 除了常见的十进制数外,还有八进制(以数字0开头)或者十六进制(0x/0X)表示法. #include < ...
- maven学习之二
三 profile介绍 可以有多个地方定义profile.定义的地方不同,它的作用范围也不同. (1) 针对于特定项目的profile配置我们可以定义在该项目的pom.xml中. (2) ...
- mysql实现高可用架构之MHA
一.简介 MHA(Master HA)是一款开源的 MySQL 的高可用程序,它为 MySQL 主从复制架构提供了 automating master failover 功能.MHA 在监控到 mas ...
- sql替换
select * ,replace(NewsContent,'src=','修改后的内容') as rep from News where id=337update News set NewsCont ...
- NodeJS寻常小毛病
在写关于NodeJS项目中常遇到的小错误 此时用到的服务器是phpstudy中的MySQL 1. First argument must be a string or Buffer 解决方法: ...
- HBuilder入门(构建h5+APP)
if(window.plus) { plusReady(); } else { //plusready事件(自带事件)调用了才可使用h5+API document.addEventListener(& ...
- Vue.js简单的应用
1:一个简单实现 下面代码部分: <body> <div id="myDiv1"> {{userName}} </div> </body& ...
- 解决thymeleaf layout布局不生效
今天使用thymeleaf layout布局时总是不生效,特此把解决问题的步骤和几个关键点记录下来备忘. 一.检查依赖 1.thymeleaf必备maven依赖: <dependency> ...
- markdown 字体颜色
Markdown是一种可以使用普通文本编辑器编写的标记语言,通过类似HTML的标记语法,它可以使普通文本内容具有一定的格式.但是它本身是不支持修改字体.字号与颜色等功能的! CSDN-markd ...
- pytesseract使用
1.安装pip install pytesseract 2.安装tesseract-ocr,下载地址:https://github.com/UB-Mannheim/tesseract/wiki,我安装 ...