我正在编写一个快速应用程序来查看一个带有一些AJAX样式调用的巨型XML文件viewgroup.我的问题session['groups']不是坚持下去.我有一些旧的阵列只有4个成员卡在某处(cookie?..).view调用时会出现该值.然后,我用最近打开的包含20多个成员的xml文件中的信息覆盖该会话成员.
但是,当viewgroup调用时,会话变量已恢复为旧值,数组中只有4个成员!
代码后跟输出.注意3个sessionStatus()电话
def sessionStatus():
print "# of groups in session = " + str(len(session['groups']))
@app.route('/')
def index():
cams = [file for file in os.listdir('xml/') if file.lower().endswith('xml')]
return render_template('index.html', cam_files=cams)
@app.route('/view/<xmlfile>')
def view(xmlfile):
path = 'xml/' + secure_filename(xmlfile)
print 'opening ' + path
xmlf = open(path, 'r')
tree = etree.parse(xmlf)
root = tree.getroot()
p = re.compile(r'Group')
groups = []
for g in root:
if (p.search(g.tag) is not None) and (g.attrib['Comment'] != 'Root'):
groups.append(Group(g.attrib['Comment']))
sessionStatus()
session['groups'] = groups
sessionStatus()
return render_template('view.html', xml=xmlfile, groups=groups)
@app.route('/viewgroup/<name>')
def viewGroup(name):
groups = session['groups']
sessionStatus()
if groups is None or len(groups) == 0:
raise Exception('invalid group name')
groups_filtered = [g for g in groups if g.name == name]
if len(groups_filtered) != 1:
raise Exception('invalid group name', groups_filtered)
group = groups_filtered[0]
prop_names = [p.name for p in group.properties]
return prop_names
Run Code Online (Sandbox Code Playgroud)
产量
opening xml/d.xml
# of groups in session = 5
# of groups in session = 57
127.0.0.1 - - [17/Aug/2011 17:27:29] "GET /view/d.xml HTTP/1.1" 200 -
127.0.0.1 - - [17/Aug/2011 17:27:29] "GET /static/ivtl.css HTTP/1.1" 304 -
127.0.0.1 - - [17/Aug/2011 17:27:29] "GET /static/jquery.js HTTP/1.1" 304 -
127.0.0.1 - - [17/Aug/2011 17:27:29] "GET /static/raphael-min.js HTTP/1.1" 304 -
127.0.0.1 - - [17/Aug/2011 17:27:29] "GET /static/ivtl.css HTTP/1.1" 304 -
127.0.0.1 - - [17/Aug/2011 17:27:29] "GET /favicon.ico HTTP/1.1" 404 -
# of groups in session = 5
127.0.0.1 - - [17/Aug/2011 17:27:31] "GET /viewgroup/DeviceInformation HTTP/1.1" 200 -
Run Code Online (Sandbox Code Playgroud)
我需要所有57个团体留下来.任何提示?
数据太大而无法序列化到会话中.现在,我将一个密钥生成一个全局字典并将该密钥存储在会话中.
gXmlData[path] = groups
Run Code Online (Sandbox Code Playgroud)
有一个问题是全球字典将永远存在于越来越多的键,但这个过程并不意味着长寿.
| 归档时间: |
|
| 查看次数: |
2950 次 |
| 最近记录: |