可以用content processor来做
try:
from django.contrib.sites.models import get_current_site
except ImportError:
from django.contrib.sites.shortcuts import get_current_site
from django.conf import settings
def site(request):
'''
Usage:
-----------------------------
settings.py
=======
TEMPLATE_CONTEXT_PROCESSORS = (
...
"bsp.context_processors.site",
....
)
templates
=======
{{ site_name }}
{{ site.name }}
'''
site = get_current_site(request)
site_name = site.name
protocol = 'https' if request.is_secure() else 'http'
domain = site.domain
return {
'site_name': site_name,
'protocol': protocol,
'domain': domain,
'site': site,
'settings': settings,
}