DEV Community

Flutter signup/login application with Django backend #1

Amartya Gaur on April 16, 2020

Introduction This series of posts intends to develop a flutter signup/login app working with API calls to Django backend. The idea is to...
Collapse
 
newsand profile image
newsand

i'm not getting whats wrong here
all my end points including
this localhost:8000/api-token-auth/
always return 404.

i can only acess localhost:8000/admin/
can you make available any sourcecode for comparisson?

Collapse
 
naveen_nirban profile image
NaveenNirban

check whether you have url for api in urls.py

Collapse
 
amartyadev profile image
Amartya Gaur

This must be the issue

Collapse
 
sayanc2000 profile image
Sayanc2000

try using 127.0.0.1:8000 or sometimes u need to add your android emulator to allowed hosts. Add 10.0.2.2 in your allowed hosts of your django project

Collapse
 
malvernbright profile image
Malvern Gondo

You'll get the following error is you try to open 127.0.0.1:8000/api/user
{
"detail": "Authentication credentials were not provided."
}

Solved it by adding the following line

REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
...
'rest_framework.authentication.SessionAuthentication',
),
'DEFAULT_PERMISSION_CLASSES': (
...
),
}

Collapse
 
im1n3_ profile image
Imane Rahmaoui • Edited

I was having the same issue, thank you this solved my problem, but for the api-token-auth/ :
{
"detail": "Method \"GET\" not allowed."
},
I'm still getting
{
"detail": "Method \"GET\" not allowed."
}

Collapse
 
cappittall profile image
Hakan Çetin • Edited

Hi Amartya,

I am having difficulties to understand creating new user.

SOLVED:

So, I was thinking always to send users own token. But at the and need superuser's auth token for creating new user :))

below was my question:

When I request : POST, localhost:8000/api/user/ with username, password, I got {
"detail": "Authentication credentials were not provided."
}
So then do I need auth token first so. I tried also :
1- POST, localhost:8000/api-token-auth/ with newusername, newpasword and I got:
{
"non_field_errors": [
"Unable to log in with provided credentials."
]
}
At the end I can not create new user. So, for creating new user, how to on?
I am sorry for this stupid question but I am newbie and stacked here

Collapse
 
haruanm profile image
Haruan Justino

Waiting for the next ones

Collapse
 
amartyadev profile image
Amartya Gaur

Next post (#2) is out: dev.to/amartyadev/flutter-signup-l...

Collapse
 
maxcmoi profile image
Maxime Deuse

Great tutorial ! For the next steps and to go faster I use DjangoModel2Dart to transform my Django models to Dart classes to transform from the json of the REST API from Django or to json.

Collapse
 
datpham2 profile image
Dat Pham

127.0.0.1:8000/api-token-auth/

{
"username": "foo",
"password": "password"
}

{"detail":"Method \"GET\" not allowed."}

Is "Method \"GET\" not allowed." expected? Or I screw up?

Collapse
 
arnumat profile image
Arnumat

part 2-3?