Saturday, November 18, 2017

Re: reg:not able to open registration form web page


Here's how I would modify the view:

views.py
--------

def SignUpFormView(request):
    user_form = 'SignUpForm'
    template_name = 'test.html'

Delete the above two lines. It appears you are mixing class-based and function-based views. In this case, you are using a function-based view.


    if request.method == 'POST':
        form = user_form(request.POST)
Should be: form = SignUpForm(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()
You can remove these commented lines, it appears as though you were trying to build the user object manually. Your firm can likely do this for you.

            return render(request, template_name, {'form':form})

If the form is valid, then you should redirect to another page/view, not return to the same page. This is a common and almost required pattern with form submissions.

return HttpResponseRedirect('/signup_complete/')

The '/signup_complete/' should resolve to another page in your urls.py and usually displays a message saying that the user was successfully signed up. You can use any URL here that can be resolved by your urls.py.




    else:
        SignUpForm()
 This line just instantiates a new form object and then throws it away. It should be used in the event that request.method is not 'POST' and you generate a new, empty form for use in your template.

form = SignUpForm()



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

You aren't passing the form object that you are creating to your template context, which is why it isn't rendering in your template.

return render(request, 'user_info/about.html', {'form': form})






test.html
---------

As far as your template goes, remove everything within the <form> definition and start with this:

<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit" value="Submit">sign up </button>
</form>



Try these notifications and let me know how that works.

If you haven't already, I would try running through the Django tutorial, which covers how to handle forms and other components of Django.


-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+unsubscribe@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%2BciUv1UKA4kL3-TqzGzt9Zgk9SFjT2y%2BzzORQszwysKBg3A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment