我曾尝试寻找资源,但无法获得任何资源。
我的django应用程序的templates文件夹中有一个html文件,
som
此处的comment.text是从模型中提取的并且是可编辑的。用户可以编辑文本值。有一个带有post方法的表格。我想在隐藏输入的value属性中发送内容可编辑文本的值。我该如何实现?
答案 0 :(得分:0)
假设您的模型具有一个名为“ selected_option”的Charfield,则遵循这些原则。
forms.py
class PracticeForm(forms.Form):
selected_value = forms.CharField(max_length=202, required=True)
selected_option = forms.CharField(max_length=202, required=True)
views.py
if request.method == 'POST':
form = PracticeForm(request.POST, request.FILES)
if form.is_valid():
foo1 = form.cleaned_data.get("selected_value")
foo2 = form.cleaned_data.get("selected_option")
html
<form contenteditable = "FALSE" action = "{% url 'clickedaccept' %}" enctype="multipart/form-data" method = "POST">
{% csrf_token %}
<input type = "hidden" name = "selected_value" value = "{{comment.id}}">
<input type = "hidden" name = "selected_option" value = "{{selected_option}}">
<button type = "submit">Click this to submit</button>
</form>