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)
| 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.""" |