On Nov 15, 2017 8:32 AM, "'Amitesh Sahay' via Django users" <
django-users@googlegroups.com> wrote:

Hello Members,

I am new to Django, and trying to create a mock Django registration page. I
am using default Django "User" model to do that, and I am not customizing
anything. Its a very simple form with 3 fields as follows:

'username','password','email'. Below are my python and html code details:


Snip...

views.py
--------

def SignUpFormView(request):
    user_form = 'SignUpForm'

    template_name = 'test.html'

    if request.method == 'POST':
        form = user_form(request.POST)
        if form.is_valid():
            form.save()
            #username = form.cleaned_data.get('username')
            #password = form.cleaned_data.get('password')
            #email = form.cleaned_data.get('email')
            #user.save()
            return render(request, template_name, {'form':form})


    else:
        SignUpForm()

    return render(request, 'user_info/about.html')


Snip...

My issue is, when trying to launch the "register" page, its not going
inside "if" condition in views.py, rather its going directly to "else"
condition.

I am tried many things under my reach, but couldn't resolve the issue, and
stuck for 2 weeks now.
Any help would be appreciated.


There are several issues with the view composition. Please refer to the
docs here and verify your syntax matches the example:

https://docs.djangoproject.com/en/1.11/topics/forms/#the-view

Your template code also suggests that you are seeing duplicate form fields
(or perhaps they are being rendered in the source but aren't visible). It's
also possible that the Django form is not being created correctly in the
first place, which is why you need to manually render the form fields, when
the {{ form.as_p }} should be doing that for you.

If you are submitting the form and getting the behavior you describe, I'm
guessing that the if statement isn't being skipped, but the values being
submitted do not match the form object in Django, causing it to fail
validation, meaning that the second if statement is coming back False.

-James

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciWNrWLhEzhM6649BsP5JByUXbsS7gvBVaKq2BkejKH7Rw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to