Django form not saving to database

So, I've been working on a Tic Tac Toe app. (Trying to learn how to user django/python)
All of my code seems to be functional, but the issue is that when the user submits the form, the data doesn't seem to go into the database at all. Because it doesn't find its way into a db table, I can't use that value on another page.
Could anyone review my code and see if you notice anything wrong?
Thanks in advance!

views.py -
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render, render_to_response
import os
from .forms import PlayerInfo
from .models import Player

def index(request):
    return render(request, 'index.html')

def start(request):
    if request.method == 'POST':
        form = PlayerInfo(request.POST)
        if form.is_valid():
            obj = Player()
            obj.player_one_name = form.cleaned_data['player_one_name']
            obj.player_two_name = form.cleaned_data['player_two_name']
            form.save()
            return HttpResponseRedirect('game/')

    else:
        form = PlayerInfo()

        return render(request, 'start.html')


def game(request):
    queryset = Player.objects.all()

    args = {'fpn': queryset.values('player_one_name'), 'spn': queryset.values('player_two_name')}
    return render_to_response('game.html', args)

Open in new window


models.py -
from django.db import models

class Player(models.Model):
    player_one_name = models.CharField(max_length=30, default='')
    player_two_name = models.CharField(max_length=30, default='')

Open in new window


forms.py -
from django import forms

class PlayerInfo(forms.Form):
    player_one_name = forms.CharField(max_length=30, label='First player name')
    player_two_name = forms.CharField(max_length=30, label='Second player name')

Open in new window


start.html -
{% extends 'base.html' %}
{% block botRow %}
    <form method="post">
        {% csrf_token %}
        {{ form.as_p }}
        <button type="submit">Submit</button>
    </form>
{% endblock %}

Open in new window


game.html -
{% extends 'base.html' %}
{% block midRow %}
    <p>{{ fpn }}</p>
    <p>{{ spn }}</p>
{% endblock %}

Open in new window

Nate ThompsonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Cyclops3590Commented:
https://docs.djangoproject.com/en/2.0/topics/forms/

look at that link.  been awhile since I've actually used the forms, but you need to pass the form variable to the template via the context parameter (you're missing that)

also, you're not doing anything with the obj instance you created.  you'd need to add obj.save().

finally, you do a obj.save() and get rid of the form.save() or you get rid of the obj lines altogether and modify your Form class to define the class Meta area to tie it to the Player model class you defined.  If you do that, then form.save() will work
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cyclops3590Commented:
I had copied/tested the given code so I know my recommendation works as the author is desiring
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Django

From novice to tech pro — start learning today.