1

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.

My Form.py is :

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 :

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

'function' object has no attribute 'MyForm'

Please Someone help :( I gotta move Forward

0

1 Answer 1

2

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(). Hence the 'function' object has no attribute 'MyForm'

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.