Skip to content
Advertisement

AttributeError: ‘NoneType’ object has no attribute ‘lower’. for django-comments-dab app

I want to use django-comments-dab but I meet this Error, AttributeError: ‘NoneType’ object has no attribute ‘lower’. Request Method: GET Request URL: http://127.0.0.1:8000/2020/9/6/test4 Django Version: 3.1.1 Exception Type: AttributeError Exception Value:
‘NoneType’ object has no attribute ‘lower’ Exception Location: D:amirblogvenvlibsite-packagescommentutils.py, line 26, in get_model_obj Python Executable: D:amirblogvenvScriptspython.exe

utils.py

def get_model_obj(app_name, model_name, model_id):
    content_type = ContentType.objects.get(app_label=app_name, model=model_name.lower())
    model_object = content_type.get_object_for_this_type(id=model_id)

    return model_object

Advertisement

Answer

model_name is None and not a string. Only strings have the lower method defined for them. Try print(model_name) and print(type(model_name)) to see that this is the case, and then fix whatever is calling get_model_obj to pass in a string.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement