Django Ajax login form

后端 未结 2 1654
终归单人心
终归单人心 2021-02-06 05:57

I am trying to submit a login form using ajax. I am confused as to how I am supposed to handle the exceptions/successful responses. I am getting a 200 OK from the server and the

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-06 06:37

    return HttpResponseRedirect(request.REQUEST.get('next', '/')) 
    

    You obviously cant use that if you are doing ajax , the client must be responsible of the redirection/display/whatever is sent back in the Ajax response. If the login is successful , send a JSON response telling the client to redirect itself( with javascript redirection ) , if it is not , send a JSON response with the list of errors and display them using javascript.

提交回复
热议问题