Monday, March 2, 2020

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

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
    }



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/556e8f34-ecd4-45b8-bd39-21504459efc3%40googlegroups.com.

No comments:

Post a Comment