本文整理汇总了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