WebFaction
Community site: login faq

Hello and Thank you in advance:

I have a form that is not saving the input data into the MySQL database. I am not getting an error, it simply isn't saving that data...

My Model:

from django.db import models from django.forms import ModelForm

class DraftInput(models.Model): player_id = models.CharField(max_length=5)

def __unicode__(self):
    return self.player_id

class DraftInputForm(ModelForm): class Meta: model = DraftInput

My View:

def player_draft_input_view(request): if request.method == 'POST': form = DraftInputForm(request.POST)

    if form.is_valid():
        form.save()
        return HttpResponseRedirect('/draft/')

else:
    form = DraftInputForm()

return render_to_response('baseball/basic_draft_pick.html',

{ 'form': form, }, context_instance=RequestContext(request))text_instance=RequestContext(request))

My template:

<!DOCTYPE html>

<html lang="en">
<head>
    <title>Basic Draft Pick Page</title>
</head>

<body>

    <form action="" method="POST">{% csrf_token %}
        {{ form.as_p }}
    <input type="submit" value="Draft" />
    </form>

</body>

</html></html>

I bet this is something really simple and I am going to kick myself, but I have been looking at this code for about 5 hours now...

Thank you,

dp

asked 20 Mar '12, 08:30

dpbklyn
111
accept rate: 0%


Try adding some print statements to your view to see how far its getting,

def player_draft_input_view(request): if request.method == 'POST': form = DraftInputForm(request.POST)
    print 'if posted'
    if form.is_valid():
        print 'is valid'
        form.save()
        return HttpResponseRedirect('/draft/')
permanent link

answered 20 Mar '12, 19:05

johns
5.4k312
accept rate: 23%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×909
×9

question asked: 20 Mar '12, 08:30

question was seen: 5,658 times

last updated: 20 Mar '12, 19:05

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2020 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM