AttributeError: 'NoneType' object has no attribute 'app_name'

170 views
Skip to first unread message

Sencer Hamarat

unread,
Mar 2, 2020, 7:55:15 AM3/2/20
to Django users
Hello, 

The project I'm working on has it's custom template context_processor.
And when unavailable URL request arrives to Django (Eg. "/wp-login.php"), the context_processor is throwing AttributeError.

Which way should I use to prevent from context processor from throwing errors?
Is it ok to wrapping return with try block and returning empty dictionary if AttributeError raised?

def resolver_context_processor(request):
    return {
        'app_name': request.resolver_match.app_name,
        'namespace': request.resolver_match.namespace,
        'url_name': request.resolver_match.url_name
    }



Naveen Arora

unread,
Mar 3, 2020, 4:24:34 AM3/3/20
to Django users
Hi, 

Can't the error be resolved ? Still, if error has to occur then you can put conditions instead of try blocks for better functioning.

Regards
Naveen Arora

Sencer Hamarat

unread,
Mar 13, 2020, 10:35:27 AM3/13/20
to Django users
Thank you for your suggestion. And sorry fro delayed answer.

My hunch is saying same thing but I want to be sure about it.

Kind Regards,
Sencer Hamarat

3 Mart 2020 Salı 12:24:34 UTC+3 tarihinde Naveen Arora yazdı:
Reply all
Reply to author
Forward
0 new messages