Check if contrib.sites is installed and return either the current ``Site`` object or a ``RequestSite`` object based on the request.
(request)
| 4 | |
| 5 | |
| 6 | def get_current_site(request): |
| 7 | """ |
| 8 | Check if contrib.sites is installed and return either the current |
| 9 | ``Site`` object or a ``RequestSite`` object based on the request. |
| 10 | """ |
| 11 | # Import is inside the function because its point is to avoid importing the |
| 12 | # Site models when django.contrib.sites isn't installed. |
| 13 | if apps.is_installed("django.contrib.sites"): |
| 14 | from .models import Site |
| 15 | |
| 16 | return Site.objects.get_current(request) |
| 17 | else: |
| 18 | return RequestSite(request) |