I am using Django as my backend for my android app. I have been handling post request using @csrf-exempt annotation with my views as I wasn't able to deal with csrf verification while sending post request from android(VOLLEY LIBRARY). Now, I have to use django.contrib.auth login and logout methods but sessions aren't working when I am sending post request from android.
I had tried enabling cookies with my request in android but that also didn't work(enabling cookies also did not solve the csrf verification failed issue).Also I tried taking csrf token from a GET request to django( django.middleware.csrf - get_token) and then passing that csrf token in headers(X-CSRF-TOKEN)in my post requests, that also didn't work.
Code that I used to enable cookies in android:
CookieManager manager = new CookieManager();
CookieHandler.setDefault(manager);
So,
1. I don't know how to use django scripts without using @csrf-exempt from android.
2. and how to use django login with android
Here is a generic response on using django as a backend: Is it possible to develop the back-end of a native mobile app using the python powered framework Django?
More specifically this is normally done with a JWT - json web token: http://www.django-rest-framework.org/api-guide/authentication/#django-rest-auth I'm sure other rest/ api frameworks exist but I normally use DRF.
Here is an example with a tutorial: Authentication with android app in a django server
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With