Python 访问链接中的字符串';s文本
我有一个大的html页面的图像,分别链接到一个html表单。表单的操作然后指向一个Django脚本,该脚本处理键值对并写入yaml文件。所有这些图像都有一个“图像id”,可以通过链接的html轻松访问(即,我有一堆Python 访问链接中的字符串';s文本,python,html,django,Python,Html,Django,我有一个大的html页面的图像,分别链接到一个html表单。表单的操作然后指向一个Django脚本,该脚本处理键值对并写入yaml文件。所有这些图像都有一个“图像id”,可以通过链接的html轻松访问(即,我有一堆 <a href .../html_form><img src=longurl.../image_id /></a href .../html_form.> 生成页面的行)。我需要某种方法来获取字符串“image\u id”,作为表单发布到dj
<a href .../html_form><img src=longurl.../image_id /></a href .../html_form.>
生成页面的行)。我需要某种方法来获取字符串“image\u id”,作为表单发布到django脚本并写入yaml文件的键值对之一('id\u of\u image':image\u id)。有人建议我如何修改表单的操作
<form name=form_name action="serverpath/django_script_function" method="post">
到
从Google上我可以看出,我应该使用某种方式动态生成html。我的问题如下:
(i) 如何访问表单或脚本中的字符串image_id以动态生成表单
(ii)对表格的唯一修改将是上述行为;我真的需要使用一些东西来动态生成html来实现这一点吗?正如我所看到的,您正在寻找一种将参数从锚元素传递到表单的方法。有很多方法可以实现这一点 例如,可以将图像id作为表单的GET参数包含在内;生成表单时,将其作为隐藏输入的值插入:
<!-- image link template -->
<a href=".../html_form?image_id={{img_id}}"><img src=".../imgs/{{img_id}}"></a>
<!-- form template; the img_id variable should be accessible from the request
object of your view, like request["image_id"] -->
<form name="form_name" action="serverpath/django_script_function">
<input name="image_id" type="hidden" value="{{img_id}}"></input>
<!-- other form fields.. -->
</form>
我花了一点时间才正确实施,但这基本上是可行的。
<!-- image link template -->
<a href=".../html_form?image_id={{img_id}}"><img src=".../imgs/{{img_id}}"></a>
<!-- form template; the img_id variable should be accessible from the request
object of your view, like request["image_id"] -->
<form name="form_name" action="serverpath/django_script_function">
<input name="image_id" type="hidden" value="{{img_id}}"></input>
<!-- other form fields.. -->
</form>