简体   繁体   中英

django {{form.as_p}} results without input widget

So here's my form :

from django import forms

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

Here's my view :

from django.shortcuts import render
from .forms import PostForm

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

and my 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'),

When I go to the url it only shows me button but no form fields. What am I doing wrong here ? I can't seem to figure that out..please help

you should remove the , in the form

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM