You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

shortcuts.py 581B

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