Here is my form code as well:
from django import forms
from django.contrib.auth.models import User
from djangoproject1.authentication.models import UserProfile

class UserForm(forms.ModelForm):
    class Meta:
        model = User
        fields = ('username','password','email',)

class UserProfileForm(forms.ModelForm):
    class Meta:
        model = UserProfile
        fields = ('phonenumber',)

On Aug 20, 11:05 am, JP <jcafar...@gmail.com> wrote:
> My main page contains a form.  Because I want the form to appear when
> I load my page my view looks like this:
>
> from djangoproject1.authentication import forms
> from django.http import HttpResponseRedirect
> from django.shortcuts import render_to_response
>
> def main(request):
>     uf = forms.UserForm()
>     upf = forms.UserProfileForm()
>     return render_to_response("authentication/index.html", {'form1':
> uf, 'form2':upf})
>
> def register(request):
>     if request.method == 'POST':
>         uf = forms.UserForm(request.POST)
>         upf = forms.UserProfileForm(request.POST)
>         if uf.is_valid() and upf.is_valid():
>             user = uf.save(commit=False)
>             user.set_password(uf.cleaned_data["password"])
>             user.save()
>             userprofile = upf.save(commit=False)
>             userprofile.user = user
>             userprofile.save()
>             return HttpResponseRedirect("/register-success/")
>     return render_to_response("authentication/index.html", {'form1':
> uf,'form2':upf})
>
> When I visit the main page, my URLConf points me to main.  If I were
> to hit submit, I would be directed to register.  The problem is, when
> I visit the page, all of the validation error messages for my fields
> are already shown for username and password.
>
> Here's my html:
>
> <h1>Register</h1>
>     <form action="/register/" method="post">
>         {{ form1.as_p }}
>         {{ form2.as_p }}
>         <input type="submit" value="Register">
>     </form>
>
> Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to