Redirect to another page in the Django view

Asked

Viewed 1,920 times

2

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

I have a registration form only with the email, when this email is filled and the user click send, I need the view to direct to the other page where the user will finish the registration, as I do?

(From page /register to page /register 1)

The way it is, I can access the registration form 1 by the url, but I want you to direct alone when you click send![inserir a descrição da imagem aqui]1

inserir a descrição da imagem aqui

py views.

# 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()})

1 answer

3


The idea is that the code at least validates the information entered in the form, so it looks 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

Send me feedback if the answer has solved your problem.

  • Hi Vitor, thanks for the help, it worked yes, it is redirecting to the other page as I wanted...

  • However what I need to solve now is the following, the user filled the email and sent, with this redirected to the second part of the form, after completed, is not saving in the database anything...

  • 1

    @Biancac. creates another question explaining what was done and what the new problem, which is easier than here in the comments :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.