check if contrib sites is installed and return either the current site object or a requestsite object based on the request import is inside the function because its point is to avoid importing the site models when django contrib sites isn t installed check if contrib sites is installed and return either the current site object or a requestsite object based on the request import is inside the function because its point is to avoid importing the site models when django contrib sites isn t installed
from django.apps import apps

from .requests import RequestSite


def get_current_site(request):
    
    
    
    if apps.is_installed("django.contrib.sites"):
        from .models import Site

        return Site.objects.get_current(request)
    else:
        return RequestSite(request)