本文整理汇总了Python中framework.config.Config.base_url方法的典型用法代码示例。如果您正苦于以下问题:Python Config.base_url方法的具体用法?Python Config.base_url怎么用?Python Config.base_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类framework.config.Config
的用法示例。
在下文中一共展示了Config.base_url方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send
# 需要导入模块: from framework.config import Config [as 别名]
# 或者: from framework.config.Config import base_url [as 别名]
def send(phone, message):
log.info("Sending sms...")
message = clean(message)
settings = Config.get('twilio')
account = twilio.Account(settings['sid'], settings['token'])
callback = Config.base_url()
if not callback:
callback = Config.get('default_host')
data = { 'From': settings['phone'],
'To': phone,
'Body': message,
'StatusCallback': "%stwilio/status" % callback
}
log.debug(data)
try:
response = account.request('/%s/Accounts/%s/SMS/Messages.json' % (settings['api'], settings['sid']), 'POST', data)
log.info("--> %s" % response)
response = json.loads(response)
smsid = response['TwilioResponse']['SMSMessage']['Sid']
status = "passed"
except Exception, e:
log.error(e)
smsid = None
status = "blocked"
示例2: render
# 需要导入模块: from framework.config import Config [as 别名]
# 或者: from framework.config.Config import base_url [as 别名]
def render(self, template_name, template_values=None, suffix="html", content_type = "text/html", status="200 OK"):
"""
Custom renderer for Change by Us templates.
@type template_name: string
@param template_name: Name of template (without extension)
@type template_values: dict
@param template_values: Values to include in the template.
@type suffix: string
@param suffix: Extension of template file.
@type content_type: string
@param content_type: HTTP header content type to output.
@rtype: ?
@returns: ?
"""
if template_values is None:
template_values = {}
# Set the user object in case it's been created since we initialized.
self.setUserObject()
# Hand all config values to the template. This method is deprecated
# but around until all templates have been updated.
config = Config.get_all()
config['base_url'] = Config.base_url()
for key in config:
if type(config[key]) is dict:
for param in config[key]:
template_values["%s_%s" % (key, param)] = config[key][param]
else:
template_values[key] = config[key]
# Give all config values as a dict in a config space.
template_values['config'] = config
# Send user data to template
if self.user:
template_values['user'] = self.user
template_values['sqla_user'] = self.sqla_user
# Add template data object
if self.template_data:
template_values['template_data'] = self.template_data
# Create full URL from web.py values
template_values['full_url'] = web.ctx.home + web.ctx.fullpath
# Check for "flash"?
if hasattr(self.session, 'flash') and self.session.flash is not None:
template_values['flash'] = self.session.flash
log.info('showing flash message: "' + self.session.flash + '"')
self.session.flash = None
self.session.invalidate()
template_values['session_id'] = self.session.session_id
# Put session values into template ??
keys = self.session.keys()
for key in keys:
template_values[key] = self.session[key]
# Set up template and Jinja
template_values['template_name'] = template_name
renderer = render_jinja(os.path.dirname(__file__) + '/../templates/',
extensions=['jinja2.ext.i18n',
'jinja2.ext.with_',])
renderer._lookup.filters.update(custom_filters.filters)
# Install the translation
translation = self.get_gettext_translation(self.get_language())
renderer._lookup.install_gettext_translations(translation)
# Insert HTML for the language chooser
curr_lang = self.get_language()
all_langs = self.get_supported_languages()
template_values['language'] = {"current": curr_lang, "list":
all_langs.iteritems()}
template_values['language_selector'] = self.choice_list(
all_langs, curr_lang)
# Set HTTP header
web.header("Content-Type", content_type)
# Debug data.
log.info("%s: %s (%s)" % (status, content_type, template_name))
log.info("*** session = %s" % self.session)
# Set status
web.ctx.status = status
# Return template and data.
return (renderer[template_name + "." + suffix](dict(d=template_values))).encode('utf-8')