Django窗体未呈现

2024-09-29 07:32:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试制作一个非模型表单,它只为类似聊天的界面获取输入文本。你知道吗

你知道吗视图.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的,很难堪:(


Tags: pyforminputgetreturnifrequestdef
1条回答
网友
1楼 · 发布于 2024-09-29 07:32:25

您没有将表单发送到shelley_test方法中的上下文-请查看render行与get_input行的区别。你知道吗

注意,尽管您根本不需要shelley_test:只要直接转到/get_input/就可以看到空表单。你知道吗

相关问题 更多 >