Reputation: 229
I am having trouble figuring out how to 're-render' a page after a POST (ajax) request. I want to know how to go about it properly so I don't fall into any bad design habits.
Render Page --> Ajax --> ??
In Views.py
def searchform(request):
if request.method == 'POST':
#Do stuff with request.POST
return render(request, 'sameapp/anotherpage.html', my_dict)
else:
return render(request, 'sameapp/thispage.html')
My AJAX POST is successful. In Firebug console, the new page is (anotherpage.html) is rendered with the appropriate data. However the page is not redirecting. What would be the appropriate pattern to use in this case (redirect_to ? ). I want to load 'anotherpage.html' with appropriate data after the POST request.
Upvotes: 2
Views: 3717
Reputation: 12273
Django and Ajax don't work that way.
If you want to have a new content with data from Ajax request, you don't need any redirect, you simply use Javascript to replace part of your current page with what you got via Ajax. That depends on the JS code you're using, some examples for jQuery can be found at http://api.jquery.com/jQuery.ajax/
Upvotes: 2