如何添加url参数到django模板url标签 [英] how to add url parameters to django template url tag

查看:296
本文介绍了如何添加url参数到django模板url标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  date = request.GET.get('date',' ')

在我的url中,我试图用这样的url模板标签这样传递参数:

 < td>< a href ={%url'health:medication-record?date = 01/01 / 2001'action ='add'pk = entry.id%}>添加到日志< / a>< / td> 

之后的参数?显然没有工作,我如何传递这个数据值以便通过get获取?

解决方案

我找到了答案这里:是否可以传递查询参数通过Django的{%url%}模板标签



只需将它们添加到最后:

 < a href ={%url myview%}?office = foobar> 
对于Django 1.5+

< a href ={%url'myview'%}?office = foobar>

[没有什么可以改进的,但是当我修复代码时,我会收到一个愚蠢的错误]


In my view to get url parameters like this:

date=request.GET.get('date','')

In my url I am trying to pass parameters in this way with the url template tag like this:

<td><a href="{% url 'health:medication-record?date=01/01/2001' action='add' pk=entry.id %}" >Add To Log</a></td>

The parameter after the ? is obviously not working, how can I pass this data value in order to retrieve in with a get?

解决方案

I found the answer here: Is it possible to pass query parameters via Django's {% url %} template tag?

Simply add them to the end:

<a href="{% url myview %}?office=foobar">
For Django 1.5+

<a href="{% url 'myview' %}?office=foobar">

[there is nothing else to improve but I'm getting a stupid error when I fix the code ticks]

这篇关于如何添加url参数到django模板url标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆