Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

177
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!