1

void reg() async { try{ http.Response response = await http.get(Uri.parse("http://10.0.2.2/api/alluser")); print(response.body); } catch(e){ print(e); } }

It is working when I am doing in chrome( web) http://127.0.0.1:8000 but not working in android emulator.

in Django's setting.py

ALLOWED_HOST = [10.0.2.2 , 127.0.0.1]

1 Answer 1

1

NOTE - Specific for connecting Android and django rest api in Flutter

I tried lot of things but connection timeout was occuring. I was using django Rest-Api

  1. go to Command Prompt type ipconfig copy ipv4 address in my case 192.168.2.4. enter image description here
  1. add 192.168.2.4 in ALLOWED_HOST =[] in django settings.py.
  2. type "python manage.py runserver 192.168.2.4:8000" to run your server. 4)In Flutter your baseurl for accesing django rest api should be "http://192.168.2.4:8000/"

This worked for me . thanks

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.