Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

47 lines (39 sloc) 1.535 kb
# -*- coding: utf-8 -*-
Various utilities
from django.conf import settings
from django.contrib.sites.models import Site
from django.template import Variable, TemplateSyntaxError, VariableDoesNotExist
def get_site_metas(with_static=False, with_media=False, extra={}):
Return metas from the current *Site* and settings
Added Site metas will be callable in templates like this ``SITE.themetaname``
This can be used in code out of a Django requests (like in management commands) or in
a context processor to get the *Site* urls.
Default metas returned :
* name: Current *Site* entry name;
* domain: Current *Site* entry domain;
* web_url: The Current *Site* entry domain prefixed with the http protocol;
Optionally it can also return ``STATIC_URL`` and ``MEDIA_URL`` if needed (like out
of Django requests).
site_current = Site.objects.get_current()
metas = {
'SITE': {
'domain': site_current.domain,
'web_url': 'http://%s' % site_current.domain, # TODO: This will be problematic in a HTTPS environment
if with_media:
metas['MEDIA_URL'] = getattr(settings, 'MEDIA_URL', '')
if with_static:
metas['STATIC_URL'] = getattr(settings, 'STATIC_URL', '')
return metas
def site_metas(request):
Context processor to add the current *Site* metas to the context
return get_site_metas()
Jump to Line
Something went wrong with that request. Please try again.