python–AttributeError,’dict’对象没有属性’iteritems’;提交到数据库时出现Flask-SQLAlchemy错误

python–AttributeError,’dict’对象没有属性’iteritems’;提交到数据库时出现Flask-SQLAlchemy错误,第1张

概述我一直试图让它运行一段时间,但似乎无济于事.我有一个webapp请求用户输入数据,然后将其提交给数据库.当我通过浏览器点击添加时,数据会传递给数据库,但是Werkzeug会发回一些错误,我在下面的跟踪中详细介绍了这些错误.我的views.py:from flask import request, flash, render_template, url_for

我一直试图让它运行一段时间,但似乎无济于事.我有一个webapp请求用户输入数据,然后将其提交给数据库.当我通过浏览器点击添加时,数据会传递给数据库,但是Werkzeug会发回一些错误,我在下面的跟踪中详细介绍了这些错误.

我的vIEws.py:

from flask import request,flash,render_template,url_for,redirectfrom aalert import app,dbimport flask_whooshalchemyfrom flask_login import LoginManager,login_required,logout_userfrom aalert.forms import *from aalert.models import User,PubInfo,PrivInfologin_manager = LoginManager()login_manager.init_app(app)login_manager.login_vIEw = 'login'@login_manager.user_loaderdef load_user(userID):    return User.query.filter(User.ID==userID).first()@app.route('/signup',methods=['GET','POST'])def signup():    form = SignupForm()    if form.valIDate_on_submit():        user = User(username=form.username.data,password = form.password.data)        db.session.add(user)        db.session.commit()        return redirect(url_for('index'))    return render_template('signup.HTML',form=form)#pubinfo index@app.route('/')def index():    entrIEs = PubInfo.query.all()    return render_template('disp_tables.HTML',entrIEs=entrIEs)@app.route('/login','POST'])def login():    form = LoginForm()    if form.valIDate_on_submit():        user = User.query.filter_by(username=form.username.data).first_or_404()        if user.is_correct_password(form.password.data):            login_user(user)            return redirect(url_for('add'))        else:            flash('Incorrect username and password!')    return render_template('login.HTML',form=form)@app.route('/show_all')@login_requireddef show_all_data():    entrIEs = PubInfo.query.join(PrivInfo,PubInfo.ID==PrivInfo.ID)    return render_template('disp_all.HTML',entrIEs)@app.route('/add',methods=['POST','GET'])#@login_required #login required to add functions,points to @login_manager.user_loaderdef insert():    form = AddEntry()    if request.method == 'POST':        if not request.form['firstname'] or not request.form['lastname'] or not request.form['age'] or not request.form['height'] or not request.form['last_loc'] or not request.form['missing_since'] or not request.form['contact_info'] or not request.form['home_address']:            flash('Please ensure all fIElds are filled out!')        else:            pubentry = PubInfo(request.form['firstname'],request.form['lastname'],request.form['age'],request.form['height'],request.form['last_loc'],request.form['missing_since'])            priventry = PrivInfo(request.form['contact_info'],request.form['home_address'])            db.session.add(pubentry)            db.session.add(priventry)            db.session.commit()            flash('Record successfully added.')            return redirect(url_for('index'))    return render_template('add.HTML',form=form)@app.route('/search','GET'])def search():    form = SearchForm()    if request.method == 'POST':        result = pubinfo.query.whoosh_search(request.form['search_query'])        return render_template('results.HTML',result=result)    return render_template('search.HTML',form=form)@app.route('/logout')def logout():    logout_user()    return redirect(url_for('index'))@app.route('/test')def test():    return redirect(url_for('login'))

错误的痕迹:

Traceback (most recent call last):  file "/home/scire/programs/python/aalert/env/lib/python3.5/site-packages/flask/app.py",line 2000,in __call__    return self.wsgi_app(environ,start_response)  file "/home/scire/programs/python/aalert/env/lib/python3.5/site-packages/flask/app.py",line 1991,in wsgi_app    response = self.make_response(self.handle_exception(e))  file "/home/scire/programs/python/aalert/env/lib/python3.5/site-packages/flask/app.py",line 1567,in handle_exception    reraise(exc_type,exc_value,tb)  file "/home/scire/programs/python/aalert/env/lib/python3.5/site-packages/flask/_compat.py",line 33,in reraise    raise value  file "/home/scire/programs/python/aalert/env/lib/python3.5/site-packages/flask/app.py",line 1988,in wsgi_app    response = self.full_dispatch_request()  file "/home/scire/programs/python/aalert/env/lib/python3.5/site-packages/flask/app.py",line 1641,in full_dispatch_request    rv = self.handle_user_exception(e)  file "/home/scire/programs/python/aalert/env/lib/python3.5/site-packages/flask/app.py",line 1544,in handle_user_exception    reraise(exc_type,line 1639,in full_dispatch_request    rv = self.dispatch_request()  file "/home/scire/programs/python/aalert/env/lib/python3.5/site-packages/flask/app.py",line 1625,in dispatch_request    return self.vIEw_functions[rule.endpoint](**req.vIEw_args)  file "/home/scire/programs/python/aalert/aalert/vIEws.py",line 75,in insert    db.session.commit()  file "/home/scire/programs/python/aalert/env/lib/python3.5/site-packages/sqlalchemy/orm/scoping.py",line 157,in do    return getattr(self.registry(),name)(*args,**@R_502_5245@)  file "/home/scire/programs/python/aalert/env/lib/python3.5/site-packages/sqlalchemy/orm/session.py",line 801,in commit    self.transaction.commit()  file "/home/scire/programs/python/aalert/env/lib/python3.5/site-packages/sqlalchemy/orm/session.py",line 399,in commit    self.session.dispatch.after_commit(self.session)  file "/home/scire/programs/python/aalert/env/lib/python3.5/site-packages/sqlalchemy/event/attr.py",line 256,in __call__    fn(*args,**kw)  file "/home/scire/programs/python/aalert/env/lib/python3.5/site-packages/flask_sqlalchemy/__init__.py",line 231,in after_commit    models_committed.send(session.app,changes=List(d.values()))  file "/home/scire/programs/python/aalert/env/lib/python3.5/site-packages/blinker/base.py",line 267,in send    for receiver in self.receivers_for(sender)]  file "/home/scire/programs/python/aalert/env/lib/python3.5/site-packages/blinker/base.py",in 
最佳答案在python3中,dict.items()执行与dict.iteritems()在Python2中所做的相同的事情.只需用items()替换iteritems()即可! 总结

以上是内存溢出为你收集整理的python – AttributeError,’dict’对象没有属性’iteritems’;提交到数据库时出现Flask-SQLAlchemy错误全部内容,希望文章能够帮你解决python – AttributeError,’dict’对象没有属性’iteritems’;提交到数据库时出现Flask-SQLAlchemy错误所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1206330.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)