使用django时存储POST变量的方法

发布于 2024-10-15 03:26:35 字数 951 浏览 1 评论 0原文

我正在使用表格搜索附近的学校并将其显示为表格。

内部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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

森末i 2024-10-22 03:26:35

执行类似的操作,

<form id="print-search" target="_blank" action="" method="post" name="providerprint">
  <input type="hidden" value="{%if query.zip %}{{query.zip}}{%else%}""{%endif%}" name="zip"/>
  <input type="hidden" value="{%if query.city %}{{query.ciyt}}{%else%}""{%endif%}" name="city"/>
  <input type="hidden" value="{%if query.state %}{{query.state}}{%else%}""{%endif%}" name="state"/>
  <input type ="submit" value="Print this Search" name="submitProviderprint"/>
</form>

不要将整个字典作为值,而是在views.py中

zip = params['zip']
city = params['city']
state = params['state']  

我们可以访问它,它对我有用。:)

Instead of taking the whole dictionary as value, do something like this

<form id="print-search" target="_blank" action="" method="post" name="providerprint">
  <input type="hidden" value="{%if query.zip %}{{query.zip}}{%else%}""{%endif%}" name="zip"/>
  <input type="hidden" value="{%if query.city %}{{query.ciyt}}{%else%}""{%endif%}" name="city"/>
  <input type="hidden" value="{%if query.state %}{{query.state}}{%else%}""{%endif%}" name="state"/>
  <input type ="submit" value="Print this Search" name="submitProviderprint"/>
</form>

inside the views.py we can access this as

zip = params['zip']
city = params['city']
state = params['state']  

and it worked for me.:)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文