本文整理匯總了Python中models.Site.get_by_hostname方法的典型用法代碼示例。如果您正苦於以下問題:Python Site.get_by_hostname方法的具體用法?Python Site.get_by_hostname怎麽用?Python Site.get_by_hostname使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models.Site
的用法示例。
在下文中一共展示了Site.get_by_hostname方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: add_site
# 需要導入模塊: from models import Site [as 別名]
# 或者: from models.Site import get_by_hostname [as 別名]
def add_site():
g.site = Site.get_by_hostname(request.host, app.config.get("DOMAIN_ROOT"))
if g.site is None:
if not app.config.get("DOMAIN_ROOT"):
return _("Config is missing a DOMAIN_ROOT: the domain name of your " "main site.")
if not app.config.get("ADMINS"):
return _("Config is missing ADMINS: used for login to your " "first site and recipient of error messages.")
name = app.config.get("ROOT_SITE_NAME", _("Your new site"))
description = _(
"This is your new site. This is also your root site, " "and this can be used to create other sites."
)
root_site, created = Site.objects.get_or_create(
domain=app.config.get("DOMAIN_ROOT"),
defaults={
"name": name,
"description": "<h1>%s</h1><p>%s</p>" % (name, description),
"owner_email": None,
"verified_email": True,
},
)
port = app.config.get("PORT", None)
url = "//%s" % root_site.domain
if port:
url += ":%d" % port
if created:
return redirect(url)
else:
return redirect("%s%s" % (url, url_for("sites")))
g.user = session.get("username", None)
if "menu" in g.site.active_modules:
g.menu, created = Menu.objects.get_or_create(site=g.site.domain)
else:
g.menu = None