Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

549
Visualizações
django - redirect to a page after registering a user

After a user successfully registers an account (creates a username and password) the webpage returns a blank registration form.

I would like to redirect to the 'landingpage' url after successful registration.

Here is the html form:

<form method="post" action="{% url 'register' %}">
{% csrf_token %}
  <table>{{ form.as_table }}</table>
    <input type="submit" value="register" />
    <input type="hidden" name="next" value="{{ next }}" />
</form>

and urls.py:

from django.views.generic.edit import CreateView
from django.contrib.auth.forms import UserCreationForm

urlpatterns = [
url('^accounts/register/', CreateView.as_view(
        template_name='registration/register.html',
        form_class=UserCreationForm,
        success_url='landingpage'
), name='register'),
url('^accounts/', include('django.contrib.auth.urls')),
url(r'^$', views.landingpage, name='landingpage'), ]

Should the success_url='landingpage' redirect to the landingpage url?

How do I redirect to the landingpage url after a successful registration?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You are looking for the reverse_lazy function, it is included inside the django.core.urlresolvers and must be imported using from django.core.urlresolvers import reverse_lazy

The code should be similar to:

from django.core.urlresolvers import reverse_lazy
# more code goes here
    url('^accounts/register/', CreateView.as_view(
        template_name='registration/register.html',
        form_class=UserCreationForm,
        success_url=reverse_lazy('landingpage')  # note the usage of reverse_lazy here 
    ), name='register'),
# also here

That function will traverse your urls and make the proper redirection after success registration.

Take a look at the django docs for more options: https://docs.djangoproject.com/en/1.11/ref/urlresolvers/#reverse-lazy

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda