django {{form.as_p}}结果,无需输入窗口小部件

时间:2018-08-17 06:56:32

标签: python django django-forms

这是我的表格:

from django import forms

class PostForm(forms.Form):
    name = forms.CharField(),
    title = forms.CharField(),

这是我的观点:

from django.shortcuts import render
from .forms import PostForm

def sign(request):
    form = PostForm()
    return render(request, 'guestbook/sign_extend.html', {'form': form})

和我的html:

{% extends 'guestbook/sign.html' %}

{% block content %}

<form action='.' method ='POST'>{% csrf_token %}

  {{ form.as_p }}

  <button type="submit">submit</button>
</form>
{% endblock %}

url:

from django.urls import path,include
from . import views

urlpatterns = [
path('sign/', views.sign,name='sign'),

当我转到url时,它仅显示按钮,但没有表单字段。我在这里做错了什么?我似乎无法弄清楚。.请帮助

1 个答案:

答案 0 :(得分:0)

您应删除表单中的,

class PostForm(forms.Form):
    name = forms.CharField()
    #                      ^^
    title = forms.CharField()
    #                       ^^