Django 错误 - 'function' 对象没有属性 'MyForm'
Django error - 'function' object has no attribute 'MyForm'
我是 Django 的新手,在使用 Django 表单时遇到了一个错误,我找不到任何相关的解决方案。
我的 Form.py 是:
from django import forms
class MyForm(forms.Form):
name = forms.CharField()
email = forms.EmailField()
text = forms.CharField(widget=forms.Textarea)
我的 views.py 是:
from django.shortcuts import render
from django.http import HttpResponse
from . import forms
# Create your views here.
def index(request):
return render(request, 'basicapp/index.html')
def forms(request):
form = forms.MyForm()
return render(request, 'basicapp/forms.html', context = { 'form' : form
})
所有路由都很好,因为我已经通过用普通 HttpResponse 替换表单进行了检查,但是 forms.py 或 views.py 中存在一些问题,因为它们的表单未在浏览器中显示错误来了
'function' object has no attribute 'MyForm'
请有人帮忙:(
我要前进
将视图的名称 def forms(request)
更改为其他名称,例如 def formView()
当您执行 forms.Myform()
时,您的函数正在调用自身。
因此 the 'function' object has no attribute 'MyForm'
我是 Django 的新手,在使用 Django 表单时遇到了一个错误,我找不到任何相关的解决方案。
我的 Form.py 是:
from django import forms
class MyForm(forms.Form):
name = forms.CharField()
email = forms.EmailField()
text = forms.CharField(widget=forms.Textarea)
我的 views.py 是:
from django.shortcuts import render
from django.http import HttpResponse
from . import forms
# Create your views here.
def index(request):
return render(request, 'basicapp/index.html')
def forms(request):
form = forms.MyForm()
return render(request, 'basicapp/forms.html', context = { 'form' : form
})
所有路由都很好,因为我已经通过用普通 HttpResponse 替换表单进行了检查,但是 forms.py 或 views.py 中存在一些问题,因为它们的表单未在浏览器中显示错误来了
'function' object has no attribute 'MyForm'
请有人帮忙:( 我要前进
将视图的名称 def forms(request)
更改为其他名称,例如 def formView()
当您执行 forms.Myform()
时,您的函数正在调用自身。
因此 the 'function' object has no attribute 'MyForm'