Redirect to another page in the Django view

0

I'm learning Django now and the idea is this:

I have a registration form with only the email, when this email is filled and the user clicks send, I need the view to go to the other page where the user will finish the registration, how do I do it?

(From page / register to page / register1)

As it is, I can access the form registration1 through the url, but I want it to be addressed by itself when I click ] 1

views.py

# coding: utf-8
from django.http import HttpResponse
from django.shortcuts import render
from portal.cadastro.forms import CadastroForm

def cadastro(request):
    if request.method == 'POST':
        form = CadastroForm(request.POST)
    return render(request, 'cadastro.html',
                        {'form': CadastroForm()})


def cadastro1(request):
    if request.method == 'POST':
        form = CadastroForm(request.POST)
    return render(request, 'cadastro1.html',
                        {'form': CadastroForm()})
    
asked by anonymous 08.08.2017 / 14:35

1 answer

2

The idea is that the code at least validates the information entered in the form, so it looks something like this:

def register(request):
    if request.method == 'POST':
        form = RegisterForm(request.POST)

        # Se as informações forem válidas
        if form.is_valid():
            user = form.save()
            # Salva os dados contidos no formulário
            user.save()
            return redirect('/URL_PARA_SER_DIRECIONADO_APOS_O_SUBMIT/')

    else:
        form = RegisterForm()

    return render(request, 'register.html', {'register_form': form})

Project Repository

Give me feedback if the answer has solved your problem.

    
08.08.2017 / 18:24