简体   繁体   中英

How to handle an error that throws an alert box and make it show an AJAX error message instead?

I'm using Django and django-voting in an app I'm making. If a user who is not authenticated tries to vote, an alert box is displayed telling them they are not authenicated. How can I catch this error and make it into a more elegant AJAX display so I can show it right on the page when it happens?

just return JSON from your view with error. How to change django default errors markup to json its an interesting question. You can write custom method and add it to error class.

def as_json(errors):
    return dict((k, map(unicode, v)) for k, v in errors.items())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM