使用django时存储POST变量的方法
我正在使用表格搜索附近的学校并将其显示为表格。
内部views.py
def 方法1: printquery = request.POST.copy() zip = printquery['zip'] 如果没有压缩: 城市 = printquery['城市'] 状态 = printquery['状态'] zip = getZip(城市,州) 结果 = zipObj.getSchools(zip); render_to_response('some.html',{'结果':结果,'查询':printquery,})
在模板内。我
<form id="print-search" target="_blank" action="" method="post" name="print">
<input type="hidden" value="{%if query%}{{query}}{%endif%} name="query"/>
<input type ="submit" value="Print the Results" name="submitPrint"/>
</form>
<table>
{% block xxx%}displays schools result {%endblock%}
</table>
单击“打印结果”按钮时 想使用“查询”, 再次搜索并在单独的页面中打印[我无法选择存储在会话 ID 中]。 我面临的问题是, {{query}}
是图灵到字符串,即 u"{'zip': u'76123'"}
我无法执行此操作类似query['zip']
, 有没有办法解决这个问题。非常欢迎提出想法。
with a form am searching schools nearby and displaying them as table.
inside views.py
def method1: printquery = request.POST.copy() zip = printquery['zip'] if not zip: city = printquery['city'] state = printquery['state'] zip = getZip(city,state) results = zipObj.getSchools(zip); render_to_response('some.html',{'results':results,'query':printquery,})
inside template
<form id="print-search" target="_blank" action="" method="post" name="print">
<input type="hidden" value="{%if query%}{{query}}{%endif%} name="query"/>
<input type ="submit" value="Print the Results" name="submitPrint"/>
</form>
<table>
{% block xxx%}displays schools result {%endblock%}
</table>
when the "Print the results" button is clicked.I want to use 'query',
do the search again and print in separate page[I have no choice of storing in session id].
Problem am facing is, {{query}}
is a turing to a string i.e.,u"{'zip': u'76123'"}
on which i cannot do something like query['zip']
,
Is there a way to solve this. Ideas are most welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
执行类似的操作,
不要将整个字典作为值,而是在views.py中
我们可以访问它,它对我有用。:)
Instead of taking the whole dictionary as value, do something like this
inside the views.py we can access this as
and it worked for me.:)