从使用 Django 模板动态创建的文本字段元素中检索数据
Retrieve data from textfield elements created dynamically with Django templates
我有这样一个 Django 视图:
def viewA(request):
if request.POST.get('Go'):
# Get all fields
all = {}
for key, values in request.POST.lists():
all[key]=values
print (all)
有了这个html:
<label>Numero de telefono</label>
<input type="text" name="phone" autocomplete="off"/>
<input type="submit" name="Go" value="Send">
当我单击 'Go' 按钮时,我得到 "all" 字典,其中包含 phone 值。好的
我的问题是我有另一个视图,我使用这样的模板创建输入元素:
<div>
{% for table, campos in tables.items %}
<div class="taable">
<label>{{table}}</label>
{% for campo in campos %}
<div class="caampo">
<input type="text" value="{{campo}}" disabled name="{{table}}:{{campo}}"/>
<select>
<option>Varchar</option>
<option>Int</option>
...
在这种情况下,当我单击 'Go' 按钮时,不会检索使用 django 模板动态创建的此元素的数据。
我怎样才能得到这个?
谢谢!
POST 个请求中未提交禁用的输入。
# your input elements
<input type="text" value="{{campo}}" disabled name="{{table}}:{{campo}}"/>
从输入中删除 disabled
属性。
也许您可以改用 readonly
。另请参阅这些相关问题:
- Disabled form inputs do not appear in the request
- values of disabled inputs will not be submitted?
我有这样一个 Django 视图:
def viewA(request):
if request.POST.get('Go'):
# Get all fields
all = {}
for key, values in request.POST.lists():
all[key]=values
print (all)
有了这个html:
<label>Numero de telefono</label>
<input type="text" name="phone" autocomplete="off"/>
<input type="submit" name="Go" value="Send">
当我单击 'Go' 按钮时,我得到 "all" 字典,其中包含 phone 值。好的
我的问题是我有另一个视图,我使用这样的模板创建输入元素:
<div>
{% for table, campos in tables.items %}
<div class="taable">
<label>{{table}}</label>
{% for campo in campos %}
<div class="caampo">
<input type="text" value="{{campo}}" disabled name="{{table}}:{{campo}}"/>
<select>
<option>Varchar</option>
<option>Int</option>
...
在这种情况下,当我单击 'Go' 按钮时,不会检索使用 django 模板动态创建的此元素的数据。 我怎样才能得到这个?
谢谢!
POST 个请求中未提交禁用的输入。
# your input elements
<input type="text" value="{{campo}}" disabled name="{{table}}:{{campo}}"/>
从输入中删除 disabled
属性。
也许您可以改用 readonly
。另请参阅这些相关问题:
- Disabled form inputs do not appear in the request
- values of disabled inputs will not be submitted?