shortcuts.py 573 B

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