T
T
tarp202020-07-21 21:22:50
Django
tarp20, 2020-07-21 21:22:50

TypeError: 'NoneType' object is not subscriptable. Where is the error in the Django application?

TypeError: 'NoneType' object is not subscriptable

if request['user_type']=='driver' and not Driver.objects.filter(user_id = user.id):
TypeError: 'NoneType' object is not subscriptable

from TarFoodApp.models import Customer,Driver

def create_user_by_type(backend , user , request , response , *args, **kwargs):
    if backend.name == 'facebook':
        avatar = 'http://graph.facebook.com/%s/picture?type=large' % response['id']
    if request['user_type'] =='driver' and not Driver.objects.filter(user_id = user.id):
        Driver.objects.create(user_id=user.id,avatar=avatar)
    elif not Customer.objects.filter(user_id=user.id):
        Customer.objects.create(user_id=user.id, avatar=avatar)


the error is most likely in request['user_type']=='driver' since I remove this code, then the request works ;

I send it with POSTMAN ; if you need to throw off more screenshots I ask the first time a question of this type))

5f1731058b88c985082692.png



Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
tarp20, 2020-07-22
@tarp20

decision

def create_user_by_type(backend , user , response , *args, **kwargs):
    request = backend.strategy.request_data()

    if backend.name == 'facebook':
        avatar = 'http://graph.facebook.com/%s/picture?type=large' % response['id']
    if request['user_type'] == 'driver' and not Driver.objects.filter(user_id = user.id):
        Driver.objects.create(user_id=user.id,avatar=avatar)
    elif not Customer.objects.filter(user_id=user.id):
        Customer.objects.create(user_id=user.id, avatar=avatar)

_
_, 2020-07-21
@mrxor

Use the debugger and you will see that either request or user is None.

A
alternativshik, 2020-07-22
@alternativshik

request['user'] there is no such thing, there is request.user the full code of the view would not hurt or where is this error

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question