简体   繁体   English

Django 错误 - 'function' 对象没有属性 'MyForm'

[英]Django error - 'function' object has no attribute 'MyForm'

I am new to Django and was working with Django forms and stuck at an error for which I am not finding any relevant solution.我是 Django 的新手,正在使用 Django 表单并遇到一个错误,我没有找到任何相关的解决方案。

My Form.py is :我的 Form.py 是:

from django import forms

class MyForm(forms.Form):
    name = forms.CharField()
    email = forms.EmailField()
    text = forms.CharField(widget=forms.Textarea)

and My views.py is :我的 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 
 })

All the routing is Fine as I have checked by replacing forms with a normal HttpResponse but there is some problem in the forms.py or views.py as they the form in not being displayed in the browser and the Error is coming所有路由都很好,因为我已经通过用普通的 HttpResponse 替换表单进行了检查,但是在 forms.py 或 views.py 中存在一些问题,因为它们没有在浏览器中显示表单并且错误即将到来

'function' object has no attribute 'MyForm'

Please Someone help :( I gotta move Forward请有人帮忙:(我得继续前进

Change the name of the view def forms(request) to something else like def formView() Your function is calling itself when you do forms.Myform() .将视图def forms(request)的名称更改为def formView()类的名称,当您执行forms.Myform()时,您的函数正在调用自身。 Hence the 'function' object has no attribute 'MyForm'因此the 'function' object has no attribute 'MyForm'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 'function' object has no attribute 'get' 错误在 django - 'function' object has no attribute 'get' error in django Django错误:“函数”对象没有属性“保存” - Django Error: 'function' object has no attribute 'save' Django属性错误:“函数”对象没有属性“ is_usable” - Django Attribute Error: 'function' object has no attribute 'is_usable' “属性错误/功能”object 在 Django 中没有属性“对象” - 'Attribute Error/ function' object has no attribute 'objects' in Django Django Feed错误:'function'对象没有属性'startswith' - Django Feed error: 'function' object has no attribute 'startswith' 使用PyCharm时发生Django错误:“'function'对象没有属性'using'” - Django Error While Using PyCharm: “'function' object has no attribute 'using'” 获取错误'function'对象没有属性'_meta'django 2.0 - Getting an error 'function' object has no attribute '_meta' django 2.0 Django属性错误:对象没有属性'表单' - Django Attribute Error: object has not attribute 'forms' 属性错误:对象在函数调用中没有属性 - Attribute error: object has no attribute on function call 属性错误“函数”对象没有属性“数据类型” - Attribute Error 'function' object has no attribute 'DataType'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM