0
list_users变量包含用户名,{{i.username}}列出所有可用用户。它列出了所有可用的用户。现在,我想传递用户名的用户名,并将用户名输入到django视图。无法从Django模板获取选项名称并传递到视图?
<select name="select">
{% for i in list_users %}
<option value="{{ i.id }}" name="username">{{ i.username }}</option>
{% endfor %}
</select>
if request.POST.get('share'):
choices = request.POST.getlist('choice')
person = request.POST.getlist('username')
for i, j in zip(choices, person):
start_date = datetime.datetime.utcnow().replace(tzinfo=utc)
a = Share(users_id=log_id, files_id=i, shared_user_id=j, shared_date=start_date)
a.save()
return HttpResponseRedirect('/uploaded_files/')
当我点击共享时,没有什么是写在共享模型。但如果我这样做:
for i in choices:
start_date = datetime.datetime.utcnow().replace(tzinfo=utc)
a = Share(users_id=log_id, files_id=i, shared_user_id=2, shared_date=start_date)
a.save()
它写在共享模型。我在做什么错误的上述代码?
'option'标记没有'name'属性,'POST'数据中的'choice'是什么? – sneawo
我已经解决了。 – user1881957