这是我的表格:
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时,它仅显示按钮,但没有表单字段。我在这里做错了什么?我似乎无法弄清楚。.请帮助
答案 0 :(得分:0)
您应删除表单中的,
class PostForm(forms.Form):
name = forms.CharField()
# ^^
title = forms.CharField()
# ^^