Skip to content

KeyError: u'SERVER_NAME' in expire_page #7

@int-ua

Description

@int-ua

I'm trying to expire cache for news pages after they've been edited by an administrator.
With this code

@receiver(post_save, sender=News)
def on_change(instance, **kwargs):
    expire_page(reverse('press:news_item', args=(instance.pk,)))

I'm getting the KeyError:

  File "project/apps/press/models.py", line 157, in on_change
    expire_page(reverse('press:news item', args=(instance.pk,)))
  File "venv/local/lib/python2.7/site-packages/cache_tools/tools.py", line 13, in expire_page
    key = get_cache_key(request)
  File "venv/local/lib/python2.7/site-packages/django/utils/cache.py", line 220, in get_cache_key
    cache_key = _generate_cache_header_key(key_prefix, request)
  File "venv/local/lib/python2.7/site-packages/django/utils/cache.py", line 202, in _generate_cache_header_key
    url = hashlib.md5(force_bytes(iri_to_uri(request.build_absolute_uri())))
  File "venv/local/lib/python2.7/site-packages/django/http/request.py", line 130, in build_absolute_uri
    self.get_host(), self.path)
  File "venv/local/lib/python2.7/site-packages/django/http/request.py", line 72, in get_host
    host = self.META['SERVER_NAME']
KeyError: u'SERVER_NAME'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions