Django/docs/2.2.x/ modules/django/contrib/sites/shortcuts

来自菜鸟教程
< Django/docs/2.2.x/ modules/django
机器人讨论 | 贡献2020年12月2日 (三) 08:14的版本 (autoload)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至:导航、​搜索

django.contrib.sites.shortcuts 源代码

from django.apps import apps


def get_current_site(request):
    """
    Check if contrib.sites is installed and return either the current
    ``Site`` object or a ``RequestSite`` object based on the request.
    """
    # Imports are inside the function because its point is to avoid importing
    # the Site models when django.contrib.sites isn't installed.
    if apps.is_installed('django.contrib.sites'):
        from .models import Site
        return Site.objects.get_current(request)
    else:
        from .requests import RequestSite
        return RequestSite(request)