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.
 
 
 
 

19 lines
624 B

  1. from __future__ import unicode_literals
  2. from django.apps import apps
  3. def get_current_site(request):
  4. """
  5. Checks if contrib.sites is installed and returns either the current
  6. ``Site`` object or a ``RequestSite`` object based on the request.
  7. """
  8. # Imports are inside the function because its point is to avoid importing
  9. # the 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. from .requests import RequestSite
  15. return RequestSite(request)