我已经编写了下面的代码来处理整个应用程序中的嵌套事务。但是当它回滚一次之后,所有事务都会回滚,直到我重新启动应用程序为止。
# method_a starts a transaction and calls method_b
def method_a():
session.begin(subtransactions=True)
try:
method_b()
session.commit() # transaction is committed here
except:
session.rollback() # rolls back the transaction
# method_b also starts a transaction, but when
# called from method_a participates in the ongoing
# transaction.
def method_b():
session.begin(subtransactions=True)
try:
session.add(SomeObject('bat', 'lala'))
session.commit() # transaction is not committed yet
except:
session.rollback() # rolls back the transaction, in this case
# the one that was initiated in method_a().
# create a Session …
Run Code Online (Sandbox Code Playgroud) 我已经使用flask框架配置了python服务器.现在我想从桌面应用程序向服务器发送请求.我的服务器位置是:http://127.0.0.1:5000/
我编写的代码可以在浏览器中运行,但我想从我的桌面应用程序访问该代码.
import flask,flask.views import os import functools
app=flask.Flask(__name__)
app.secret_key="xyz" users={'pravin':'abc'}
class Main(flask.views.MethodView):
def get(self):
return flask.render_template('index.html')
def post(self):
if 'logout' in flask.request.form:
flask.session.pop('username',None)
return flask.redirect(flask.url_for('index'))
required=['username','passwd']
for r in required:
if r not in flask.request.form:
flask.flash("Error: {0} is required.".format(r))
return flask.redirect(flask.url_for('index'))
username=flask.request.form['username']
password=flask.request.form['passwd']
if username in users and users[username]==password:
flask.session['username']=username
else:
flask.flash("Username doesn`t exist or incorrect password.")
return flask.redirect(flask.url_for('index'))
app.add_url_rule("/",view_func=Main.as_view("index"),methods=["GET","POST"])
app.debug=True
app.run()
Run Code Online (Sandbox Code Playgroud) form_shift
是表格名称
tblSession
是QTableWidget
对象
shift_id=form_shift.tblSession.item(1,0).text()
Run Code Online (Sandbox Code Playgroud)
错误:
AttributeError: 'NoneType' object has no attribute 'text'
Run Code Online (Sandbox Code Playgroud)