0

is valid always fails, what am i doing wrong?

error.html keeps getting triggered

any help would be appreciated

filler stuff filler stufffiller stuff filler stufffiller stuff filler stuff


views.py

from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from django.template import RequestContext
from django.core.context_processors import csrf
from django.contrib.auth.decorators import login_required

from user_profile.models import UserProfile
from forms import UserProfileForm

from drinker.models import Drinker
from drinker.forms import RegistrationForm


from django.contrib.auth.models import User
from django.http import HttpResponseRedirect

@login_required
def your_profile(request):
    if request.method == 'POST':
        formBio = UserProfileForm(request.POST)
        formDrinker = RegistrationForm(request.POST)
        if formBio.is_valid() and formDrinker.is_valid():
            userProfile = UserProfile.objects.get(user=request.user)
            bio = form.cleaned_data['bio']
            userProfile.bio = bio

            userDrinker = Drinker.objects.get(user=request.user)
            birthday = form.cleaned_data['birthday']
            userDrinker.birthday = birthday
            userDrinker.save()

            userDrinker = Drinker.objects.get(user=request.user)
            name = form.cleaned_data['name']
            userDrinker.name = name
            userDrinker.save()

            return HttpResponseRedirect('/user/profile/' + str(userProfile.id))
        else:
            return HttpResponseRedirect('/user/error/')
    return HttpResponseRedirect('/user/update_profile')
tomter2014
  • 163
  • 2
  • 11
  • You are processing two forms at once? This should not work, there should be one transmitted on send only. – Klaus D. Nov 30 '14 at 11:19

1 Answers1

0

Your POST request contains two forms. You need to tell Django what POST data correspond to what form. You can use the prefix argument in your forms.

See Proper way to handle multiple forms on one page in Django and https://docs.djangoproject.com/en/dev/ref/forms/api/#prefixes-for-forms.

Community
  • 1
  • 1
mimo
  • 2,062
  • 20
  • 44