表单不在Django 1.8中显示

时间:2018-02-17 17:01:29

标签: python django forms

我正在使用Django 1.8和Python 3.5制作表单 但是表格没有出现,IDK为什么?

这是我的文件

urlpatterns = [
    url(r'^login', 'login.views.login', name='login'),
    url(r'^admin/', include(admin.site.urls)),
] + static(settings.STATIC_URL , document_root=settings.STATIC_ROOT)

登录/ view.py ==

from django.shortcuts import render
from .forms import allusers1
# Create your views here.
def login(request):
    form1=allusers1()
    context = {
         "form1": form1

     }
    return render(request, "login.html",context)

登录/ forms.py ==

from django import forms

from .models import allusers1

class signupform(forms.ModelForm):
    class Meta:
        model = allusers1
        fields = ['name','phoneno']

登录/ models.py

from django.db import models

# Create your models here.
class allusers1(models.Model):
    name=models.CharField(max_length=400)
    phoneno=models.CharField(max_length=10)
    otp=models.IntegerField()

    # def __str__(self):
    #     return self.name

的login.html

{{form1}}

输出

allusers1 object

但输出应该是名称和输入的电子邮件字段

什么是错误?

1 个答案:

答案 0 :(得分:0)

您的表单实际上是signupform,而不是allusers1

views.py 中,您应该像这样导入表单:

from django.shortcuts import render
from .forms import signupform  # <= here
# Create your views here.
def login(request):
    form1=signupform()  # <= and here
    context = {
         "form1": form1

     }
    return render(request, "login.html",context)