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

179
Visualizações
Django render not working when redirected from another view

I have two views as follows

def home(request):
    levels = levelData.objects.all()
    context ={
            "levels" : levels
    }
    print "abcde"
    return render(request, 'home.html', context)

and the other one

def create(request):
    if request.method == "POST":
        # doing something with data with saveData as variable of model type
        saveData.save()
        return redirect('home')
    return render(request, 'create.html')

Now, inside the create view, I wish to redirect to home view after saving data. Redirect is working fine and it's being redirected to home as the print statement in home view is executed and "abcde" is printed in terminal. But, home.html does not get rendered and it remains on create.html. Also, the url doesn't change.

This is home view in my urls.py

url(r'^$', home, name='home'),

What am I doing wrong?

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

0

If you are posting through AJAX, you cannot do that.You have to do like

window.location.href = '/redirecturl/'

in AJAX success callback.

about 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