[英]Pass variable from template to view django
The main goal is to click a link then have a plot be generated based on the link clicked.主要目标是单击一个链接,然后根据单击的链接生成一个图。
I think if I am able to some how pass a variable(string needed for bar plot) from the link clicked on the template, to the views I can create the plot.我想如果我能够通过单击模板的链接将变量(条形图所需的字符串)传递给视图,我可以创建绘图。
In short, I would click the link this passes a variable to the views then the views would create a plot and pass it to a template.简而言之,我会单击将变量传递给视图的链接,然后视图将创建一个图并将其传递给模板。
Any help is appreciated任何帮助表示赞赏
Just use GET
parameters to identify which link was clicked.只需使用GET
参数来识别单击了哪个链接。
<a href="/your/url/?parameter_name=value_01">Show with value_01</a>
<a href="/your/url/?parameter_name=value_02">Show with value_02</a>
<a href="/your/url/?parameter_name=value_03">Show with value_03</a>
def your_view(request):
if request.GET.get('parameter_name') == 'value_01':
# first link clicked
elif request.GET.get('parameter_name') == 'value_02':
# second link clicked
elif request.GET.get('parameter_name') == 'value_03':
# third link clicked
# ... your code
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.