Esempio n. 1
0
def register(request):  
    try :
        if request.session['username'] :
            return HttpResponseRedirect('/success/')
    except:
        pass

        #A Http Post
        if request.method =='POST' :
            form = RegisterForm(request.POST)

            #Checking the validity of the form
            if form.is_valid():
                #then Save the form
                form.save()
                #Now send the user to home page
                return HttpResponseRedirect('/login/')
            else:
                #the form contains error return  the error
                print (form.errors)

        else:
            #If the request was not a POST method then show the form to enter the details
            form = RegisterForm()

            #Render the form with error if supplied
        return render(request,'blogapp/register.html',{'form':form})
Esempio n. 2
0
def register(request):
    # A Http Post
    if request.method == "POST":
        form = RegisterForm(request.POST)

        # Checking the vlaidity of the form
        if form.is_valid():
            # then Save the form
            form.save()
            # Now send the user to home page
            return HttpResponseRedirect("/login/")
        else:
            # the form contains error return  the error
            print(form.errors)

    else:
        # If the request was not a POST method then show the form to enter the details
        form = RegisterForm()

        # Render the form with error if supplied
    return render(request, "blogapp/register.html", {"form": form})