我有一个在瓶子上运行的python脚本,它在调用时返回json数据。问题是,如果我在浏览器上调用URL并保持刷新(按F5),结果似乎是每次刷新而不是从数据库中获取新数据。例如。如果我在查询1上得到1个结果,那么我刷新浏览器,我将获得2个结果而不是1个结果。第二个refesh的第一个结果将是来自初始查询的数据,这意味着“脚本/浏览器”没有忘记初始查询。
获取新数据的唯一方法是当我通过$python3.2 myscript.py
有没有办法提取新数据的默认行为,它不会缓存最后的结果?
这是我的剧本:
@route('/get_member', method = "GET")
def get_member():
key = request.query.key
search = request.query.search
if search == None:
return "blank search parameter"
elif search == "":
return "blank search parameter"
elif len(str(search)) < 2:
return "search variable too short"
hmn = None
result = []
params ={}
try:
if key == 'id':
if valid_integer(search) == False:
return "search should be numbers only"
mbr = Member()
hmn = mbr.get_id(search)
else:
return "wrong key provided"
if hmn != None:
result.append(hmn)
hmn = None
#save query to file
file_name = get_day()
f = open(file_name + ".log", "a")
print ("Name of the file: ", f.name)
f.write(get_time_now() + str(result) + "\n")
#Return jason file
from json import dumps
response.content_type = 'application/json'
return dumps(result)
result = None
except:
return "oops, an error occured"
finally:
result = None