DjangoRestFramework

20 views
Skip to first unread message

Minhaj Nadeem

unread,
Apr 8, 2019, 7:23:55 AM4/8/19
to django...@googlegroups.com
Hi everyone,
I am new to Django Rest Framework. I have developed a program using pyCharm. A local url that gets list of users. It is working fine on web, I tried to execute this API from android App but it return null response. please tell me how can i have working API on android App. Thank you!

--
Best Regards,
Muhammad Minhaj Nadeem
Software engineer

Mamadou Harouna Diallo

unread,
Apr 8, 2019, 8:48:05 AM4/8/19
to django...@googlegroups.com
Lorsque vous utiliser le cURL votre api vous retourne t-elle toutes les données dont vous avez besoin ?
si c'est le cas, avez vous pris en compte les cors dans votre API, cela peut parfois être également une source d'erreur pour ceux qui consomme l'API.

Vous pouvez installer les cors avec :
pip install django-cors-headers
puis ajout l'application dans votre INSTALLED_APPS

INSTALLED_APPS = (
    ...
    'corsheaders',
    ...
)
en suite dans votre middleware :

MIDDLEWARE_CLASSES = [ ... 'corsheaders.middleware.CorsMiddleware', 'django.middleware.common.CommonMiddleware', ... ]
mettre CoreMiddleware le plus haut possible.

En suite ajouter  CORS_ORIGIN_ALLOW_ALL=True (dans votre settings.py)

Puis en fin : ajouter les hotes autoriser:

CORS_ORIGIN_WHITELIST = ( 'hostname.example.com', 'localhost:8000', '127.0.0.1:9000' )
NB : préciser les votres.


Et si vous vérifiez tout cela et que le problème ne vient pas de la, merci de vérifier votre code java(ce service qui consomme votre API)  

J'espère que cela va vous aider, Merci !

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAAwTtYi9yKWEGPOqwze6s-dY995PrWPdfVWV4egnc9p4K9vTMw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages