我正在尝试制作一个非模型表单,它只为类似聊天的界面获取输入文本。你知道吗
你知道吗视图.py你知道吗
def get_input(request):
if request.method == 'POST':
form = inputForm(request.POST)
if form.is_valid():
return HttpResponseRedirect('/thanks/')
else:
form = inputForm()
return render(request, 'index.html', {'form': form})
def shelley_test(request):
form = inputForm()
return render(request, 'shelley_test.html')
你知道吗表格.py你知道吗
from django import forms
class inputForm(forms.Form):
input = forms.CharField(label='input field')
雪莱_测试.html你知道吗
<form action="/get_input/" method="get">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Submit" />
</form>
请帮帮我。我是刚到django的,很难堪:(
您没有将表单发送到
shelley_test
方法中的上下文-请查看render
行与get_input
行的区别。你知道吗注意,尽管您根本不需要
shelley_test
:只要直接转到/get_input/
就可以看到空表单。你知道吗相关问题 更多 >
编程相关推荐