Q:

django models error when inputting form data

Full Traceback
I am a beginner in django, and am having some trouble inputting form data to database. I am getting a 
`TypeError at /Info/
Info() got an unexpected keyword argument 'email'`

when I feel I am doing it correctly
Here is my models.py
from django.db import models

# Create your models here.

class Info(models.Model):
    address = models.CharField(max_length=70)
    email = models.EmailField(max_length=32)

My Views.py
def Info(request):
    if request.method == 'POST':
        form = InfoForm(request.POST)
        if form.is_valid():
            address = request.POST.get('address')
            email = request.POST.get('email')
            Facts = Info(email = email)
            Facts.save()
        else:
            form = InfoForm()
    return render(request, 'index/index.html', {'title': 'Info'})

def index(request):

    return render(request, 'index/index.html', {'title': 'Home'})

My Forms.py
from django import forms
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm

class InfoForm(forms.Form):
   address = forms.CharField()
   email = forms.EmailField()

Thanks. Any help is appreciated.

A:

Awesome that you are trying out something new, Django is an excellent framework and I hope you learn lots. So a couple of things I've noticed in your code that may help. So the reason you are having that error in particular is because you have a clash in your naming. You use Info as your class name and also for your view. Functions should typically be lower-cased. So if you look below, this should resolve your error. But I agree with the comment posted earlier that you perhaps look into ModelForm https://docs.djangoproject.com/en/2.1/topics/forms/modelforms/#django.forms.ModelForm
from wherever.models import Info
from wherever.forms import InfoForm

def info_view(request):
    if request.method == 'POST':
        form = InfoForm(request.POST)
        if form.is_valid():
            address = request.POST.get('address')
            email = request.POST.get('email')
            facts = Info(email=email, address=address)
            facts.save()
        else:
            form = InfoForm()
    return render(request, 'index/index.html', {'title': 'Info'})

