【发布时间】:2012-12-05 23:48:13
【问题描述】:
我的视图如下所示:
def selectCity(request, the_city):
request.session["ciudad"] = the_city
city = request.session["ciudad"]
return HttpResponse('Ciudad has been set' + ": " + city)
还有一个如下所示的 URL:
url(r'^set/$', views.selectCity, {'the_city': 'gye'}, name='ciudad'),
现在,当我访问 /set/ 时,我会从 url {'the_city': 'gye'} 中的 dict 上的值设置会话变量得到适当的响应
现在,我想做的是修改我的程序,以便我可以从不同的模板 (index.html) 调用“ciudad”网址并设置适当的会话变量。 所以我会使用反向 URL 匹配和一个额外的参数来调用它:
<div class="modal-body">
<a tabindex="-1" href="{% url ciudad 'the_city':'uio' %}">Quito</a>
<br/>
<a tabindex="-1" href="{% url ciudad 'the_city':'gye' %}">Guayaquil</a>
</div>
我已尝试以各种方式修改 url 和视图以及反向 url 调用以尝试使其正常工作,但我似乎无法弄清楚。 我真的很感激一些指点。
【问题讨论】:
标签: python django django-templates django-views django-urls