MCPcopy
hub / github.com/django/django / get_current

Method get_current

django/contrib/sites/models.py:48–68  ·  view source on GitHub ↗

Return the current Site based on the SITE_ID in the project's settings. If SITE_ID isn't defined, return the site with domain matching request.get_host(). The ``Site`` object is cached the first time it's retrieved from the database.

(self, request=None)

Source from the content-addressed store, hash-verified

46 return SITE_CACHE[domain]
47
48 def get_current(self, request=None):
49 """
50 Return the current Site based on the SITE_ID in the project's settings.
51 If SITE_ID isn't defined, return the site with domain matching
52 request.get_host(). The ``Site`` object is cached the first time it's
53 retrieved from the database.
54 """
55 from django.conf import settings
56
57 if getattr(settings, "SITE_ID", ""):
58 site_id = settings.SITE_ID
59 return self._get_site_by_id(site_id)
60 elif request:
61 return self._get_site_by_request(request)
62
63 raise ImproperlyConfigured(
64 'You\'re using the Django "sites framework" without having '
65 "set the SITE_ID setting. Create a site in your database and "
66 "set the SITE_ID setting or pass a request to "
67 "Site.objects.get_current() to fix this error."
68 )
69
70 def clear_cache(self):
71 """Clear the ``Site`` object cache."""

Callers 8

get_current_siteFunction · 0.80
itemsMethod · 0.80
get_domainMethod · 0.80
test_site_managerMethod · 0.80
test_site_cacheMethod · 0.80
setUpTestDataMethod · 0.80

Calls 3

_get_site_by_idMethod · 0.95
_get_site_by_requestMethod · 0.95

Tested by 5

test_site_managerMethod · 0.64
test_site_cacheMethod · 0.64
setUpTestDataMethod · 0.64