【问题标题】:django 1.7 redirect after an ajax callajax调用后的django 1.7重定向
【发布时间】:2015-03-17 16:21:47
【问题描述】:

我有一个通过 ajax 请求调用的视图方法。在请求完成时,我希望用户被重定向到仪表板,但我无法重定向到工作。

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

【问题讨论】:

  • 如果您总是想重定向,我想知道您为什么还要使用 Ajax。

标签: django django-1.7


【解决方案1】:

返回 HttpResponse('success') 并通过 JavaScript 进行重定向。

【讨论】:

    猜你喜欢
    • 2016-03-13
    • 1970-01-01
    • 1970-01-01
    • 2020-10-19
    • 2014-07-11
    • 2017-04-09
    • 2020-07-27
    • 2010-09-15
    相关资源
    最近更新 更多