Search code examples
djangodjango-1.7

django 1.7 redirect after an ajax call


I have an view method that is called via an ajax request. On request completion I want user to be redirect to the dashboard but I cant get redirect to work.

def apply(request):
    if request.is_ajax():
        try:
            application_type = request.POST['application_type']
            if application_type == 'job':
                apply_job(request)
            elif application_type == 'availability':
                apply_availability(request)                
            return redirect('useraccount_dashboard')
        except KeyError:
            messages.error(request, 'Request failed!')
            return HttpResponseRedirect(reverse_lazy('useraccount_dashboard'))
    else:
        raise Http404

Solution

  • Return HttpResponse('success') and make redirect via JavaScript.