I have a web application built in Django 1.3. We have also provided API functions, which return json, which is used by mobile app. Now, for authentication we use login_required decorator in views. But, for API this does not work, because it returns HTML (redirect to login page) and mobile has its own login screen. We want to return json response which asks the user to login.
How can we implement this?
You can write your own decorator. See the code for login_required at https://github.com/django/django/blob/master/django/contrib/auth/decorators.py.
You should replace redirect_to_login with code to return a json error message instead.