所以我试图让用户只使用烧瓶服务器从数据库中一次检索50个查询。这是我的逻辑
server.py
@app.route('/getEmployees/<userid>')
def all(userid):
# Allow the user to specify an offset via querystring
offset = request.args.get('offset')
# Allow user to specify limit but default to 50
limit = request.args.get('limit', 50)
if offset is None:
# Look in the session and default to 0 if not defined
offset = session.get('offset', 0)
g.db = connect_db()
cur = g.db.execute('select * from employees limit %d offset %d' % (limit, int(offset)))
entry=[dict(emp_no=row[0],birth_date=row[1],first_name=row[2],last_name=row[3],gender=row[4],hire_date=row[5]) for row in cur.fetchall()]
g.db.close()
session['offset']= offset + limit;
return str(entry)
现在gooduser.py
from timeit import default_timer
import urllib2
userid='gooduser'
start=default_timer()
req = urllib2.Request('http://0.0.0.0:5000/getEmployees/'+str(userid))
response = urllib2.urlopen(req)
the_page = response.read()
duration = default_timer() - start
print the_page
print duration
在终端中多次运行python gooduser.py,每次都给我50个元组。但是当我在我的浏览器上转到http://0.0.0.0:5000/getEmployees/gooduser时,只要我刷新它就会给我下50个条目。 我如何让gooduser.py在终端上工作并获得接下来的50个条目。