在制作表单时,Django中没有输入字段

时间:2016-10-11 16:45:18

标签: django

我是django的新手,我正在尝试创建表单,但每当我运行它时,我最终会得到一个没有输入字段的提交按钮。如果您发现任何其他错误,请不要犹豫告诉我。

views.py

from django.shortcuts import render
from django.http import HttpResponse

from .forms import *

def form(request):
if request.method == 'POST':
    form = forma(request.POST)
    if form.is_valid():
        return HttpResponseRedirect('index.html')
else:
    form = forma()
return render(request, 'action.html', {"form":form})

def action(request):
    return render(request, 'action.html')

** forms.py **

from django import forms

class forma(forms.Form):
    your_name = forms.CharField(label='Your name', max_length=100)

的index.html

<body>
    <section id = "sec">
    <h1>... </h1>
    <h3> ... </h3>
    <h4> ... <h4>
    <a href = "/papas"> <button> ... </button> </a>
    <p>{{hola}} alo {{darwich}}</p>
    <form action= "action.html" method="post">
    {% csrf_token %}
    {{ form }}
    <input type="submit" value="Submit" />
</form>
    </section>
<body>

0 个答案:

没有答案