title: Django: Save Form Data to Database
body: <p>I'm using a form in my Django project to get people's name and number for later contact. Followed several guides including the Django docs but it doesn't seem to work. My test POST doesn't appear in admin and it can't be accessed via the manage.py shell either. I left in the multi-line comment in my code to show another method I was trying just in case. Getting no errors thrown in my manage.py runserver logs either.</p>
  
  <p>Form:</p>
  
  <pre><code>from django import forms
  
  class SubscribeForm(forms.Form):
    name = forms.CharField(label='Your Name', max_length=100)
    phone_number = forms.CharField(label='Phone Number', max_length=12, min_length=10)
  </code></pre>
  
  <p>Template:</p>
  
  <pre><code>&lt;form action="/success/" method="post"&gt;
    {% csrf_token %}
    {{ form }}
    &lt;input type="submit" value="Submit" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>from django.http import HttpResponse, HttpResponseRedirect
  from django.shortcuts import render
  from datetime import datetime
  
  from .models import Person
  from .forms import SubscribeForm
  
  def home(request):
    # if this is a POST request we need to process the form data
    if request.method == 'POST':
      # create a form instance and populate it with data from the request:
      form = SubscribeForm(request.POST)
      # check whether it's valid:
      if form.is_valid():
          # process the data in form.cleaned_data as required
          p = form.save()
          '''
          name = form.cleaned_data['name']
          number = form.cleaned_date['phone_number']
          p = Person(name=name, phone_number=number, date_subscribed=datetime.now(), messages_recieved=0)
          p.save()
          '''
          # redirect to a new URL:
          return HttpResponseRedirect('/success/')
    # if a GET (or any other method) we'll create a blank form    
    else: 
      form = SubscribeForm()
  
    return render(request, 'texting/index.html', {'form': form})
  </code></pre>
  
  <p>I've watched several videos and read many SO pages, but still doesn't seem to work.</p>