本文整理汇总了Python中quokka.core.templates.render_template函数的典型用法代码示例。如果您正苦于以下问题:Python render_template函数的具体用法?Python render_template怎么用?Python render_template使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了render_template函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: confirmation
def confirmation(self): # redirect_url
context = {}
transaction_param = self.config.get(
'transaction_param',
self.pg.config.get('TRANSACTION_PARAM', 'transaction_id')
)
transaction_code = request.args.get(transaction_param)
if transaction_code:
context['transaction_code'] = transaction_code
response = self.pg.check_transaction(transaction_code)
logger.debug(response.xml)
reference = getattr(response, 'reference', None)
if not reference:
logger.error("no reference found")
return render_template('cart/simple_confirmation.html',
**context)
prefix = self.pg.config.get('REFERENCE_PREFIX', '') or ''
prefix = prefix.replace('%s', '')
status = getattr(response, 'status', None)
# get grossAmount to populate a payment with methods
try:
# self.cart = Cart.objects.get(
# reference_code=reference.replace(PREFIX, '')
# )
ref = reference.replace(prefix, '')
qs = Cart.objects.filter(
reference_code=ref
) or Cart.objects.filter(id=ref)
if not qs:
return "Cart not found"
self.cart = qs[0]
self.cart.set_status(
self.STATUS_MAP.get(str(status), self.cart.status)
)
self.cart.transaction_code = transaction_code
msg = "Status changed to: %s" % self.cart.status
self.cart.addlog(msg)
context['cart'] = self.cart
logger.info("Cart updated")
fee_amount = getattr(response, 'feeAmount', None)
if fee_amount:
self.cart.set_tax(fee_amount)
msg = "Tax set to: %s" % fee_amount
self.cart.addlog(msg)
# send response to reference and products
self.cart.send_response(response, 'pagseguro')
return render_template('cart/confirmation.html', **context)
except Exception as e:
msg = "Error in confirmation: {} - {}".format(reference, e)
logger.error(msg)
return render_template('cart/simple_confirmation.html', **context)
示例2: process
def process(self, *args, **kwargs):
kwargs.update(self._record.config)
kwargs.update(self.cart.config)
response = self.pg.checkout(**kwargs)
self.cart.addlog(
(
"lib checkout data:{pg.data}\n"
" code:{r.code} url:{r.payment_url}\n"
" errors: {r.errors}\n"
" xml: {r.xml}\n"
).format(
pg=self.pg, r=response
)
)
if not response.errors:
self.cart.checkout_code = response.code
#self.cart.status = 'checked_out' # should set on redirect url
self.cart.addlog("PagSeguro processed! {}".format(response.code))
return redirect(response.payment_url)
else:
self.cart.addlog(
'PagSeguro error processing {}'.format(
response.errors
)
)
return render_template("cart/checkout_error.html",
response=response, cart=self.cart)
示例3: post
def post(self, long_slug):
context = self.get_context_by_long_slug(long_slug)
form = context.get('form')
#if form.validate():
# comment = Comment()
# form.populate_obj(comment)
#
# content = context.get('content')
# content.comments.append(comment)
# content.save()
#
# return redirect(url_for('.detail', long_slug=long_slug))
if form.validate():
answer = Answer()
form.populate_obj(answer)
question = context.get('question')
question.tries.append(answer)
question.save()
#candidate = context.get('candidate')
#candidate.answers.append(answer)
#candidate.save()
return redirect(url_for('.detail', long_slug=long_slug))
return render_template(
self.get_template_names(),
theme=self.question.get_themes(),
**context
)
示例4: post
def post(self):
form = self.form(request.form)
if form.validate():
user = get_current_user()
avatar_file_path = user.avatar_file_path
avatar = request.files.get('avatar')
if avatar:
filename = secure_filename(avatar.filename)
avatar_file_path = os.path.join(
'avatars', str(user.id), filename
)
path = os.path.join(lazy_media_path(), avatar_file_path)
if not os.path.exists(os.path.dirname(path)):
os.makedirs(os.path.dirname(path), 0o777)
avatar.save(path)
form.populate_obj(user)
user.avatar_file_path = avatar_file_path
if avatar:
user.use_avatar_from = 'upload'
user.username = User.generate_username(
user.username or user.name, user=user
)
self.update_user_links(request.form, user)
user.save()
flash('Profile saved!', 'alert')
return redirect(
request.args.get('next') or
url_for('quokka.modules.accounts.profile_edit')
)
else:
flash('Error ocurred!', 'alert error') # form errors
return render_template('accounts/profile_edit.html', form=form)
示例5: get
def get(self, long_slug):
now = datetime.now()
path = long_slug.split('/')
mpath = ",".join(path)
mpath = ",{0},".format(mpath)
channel = Channel.objects.get_or_404(mpath=mpath)
if channel.render_content:
return ContentDetail().get(
channel.render_content.content.long_slug, True)
self.channel = channel
base_filters = {}
filters = {
'published': True,
'available_at__lte': now,
'show_on_channel': True
}
if not channel.is_homepage:
base_filters['__raw__'] = {
'mpath': {'$regex': "^{0}".format(mpath)}}
filters.update(channel.get_content_filters())
contents = Content.objects(**base_filters).filter(**filters)
themes = channel.get_themes()
return render_template(self.get_template_names(),
theme=themes,
contents=contents,
channel=channel)
示例6: get
def get(self, long_slug):
now = datetime.now()
path = long_slug.split('/')
mpath = ",".join(path)
mpath = ",{0},".format(mpath)
channel = Channel.objects.get_or_404(mpath=mpath, published=True)
# if channel.is_homepage and request.path != "/":
# return redirect("/")
if channel.redirect_url:
return redirect(channel.redirect_url)
if channel.render_content:
return ContentDetail().get(
channel.render_content.content.long_slug, True)
self.channel = channel
base_filters = {}
filters = {
'published': True,
'available_at__lte': now,
'show_on_channel': True
}
if not channel.is_homepage:
base_filters['__raw__'] = {
'mpath': {'$regex': "^{0}".format(mpath)}}
filters.update(channel.get_content_filters())
contents = Content.objects(**base_filters).filter(**filters)
if current_app.config.get("PAGINATION_ENABLED", True):
pagination_arg = current_app.config.get("PAGINATION_ARG", "page")
page = request.args.get(pagination_arg, 1)
per_page = (
request.args.get('per_page') or
channel.per_page or
current_app.config.get("PAGINATION_PER_PAGE", 10)
)
contents = contents.paginate(page=int(page),
per_page=int(per_page))
# this can be overkill! try another solution
# to filter out content in unpublished channels
# when homepage and also in blocks
# contents = [content for content in contents
# if content.channel.published]
themes = channel.get_themes()
return render_template(self.get_template_names(),
theme=themes,
contents=contents,
channel=channel)
示例7: get
def get(self, long_slug):
context = self.get_context(long_slug)
if isinstance(context, collections.Callable):
return context
return render_template(
self.get_template_names(),
theme=self.content.get_themes(),
**context
)
示例8: process_pipeline
def process_pipeline(self):
if not self.items:
return render_template('cart/empty_cart.html',
url=self.continue_shopping_url)
pipelines = self.build_pipeline()
index = session.get('cart_pipeline_index', 0)
pipeline = import_string(pipelines[index])
return pipeline(self, pipelines, index)._preprocess()
示例9: method_not_allowed_page
def method_not_allowed_page(error):
"""
The method specified in the Request-Line is not allowed for the
resource
identified by the Request-URI. The response MUST include an
Allow header
containing a list of valid methods for the requested resource.
"""
return render_template("errors/method_not_allowed.html"), 405
示例10: get
def get(self, pretty_slug, render_content=False):
context = self.get_context_by_pretty_slug(pretty_slug, render_content)
if not render_content and isinstance(context, collections.Callable):
return context
return render_template(
self.get_template_names(),
theme=self.question.get_themes(),
**context
)
示例11: dispatch_aliases
def dispatch_aliases():
"""
When ALIASES_ENABLED == True
This method handle 3 QuokkaCMS features:
1. Fixed aliases
Alias is defined in ALIASES_MAP setting as a dictionary
2. Managed Redirects
Alias defined in database
3. Channel and Content aliases
Alias defined in specific channel or content
ALIASES_MAP
keys are long_slug
keys should always start with /
& end with / or extension.
{
"/team/": {
"alias_type": "endpoint|long_slug|url|string|template",
"action": "redirect|render",
"to": "authors|/articles/science.html|http://t.co|'<b>Hello</b>'",
"published": True,
"available_at": "",
"available_until: "",
}
}
- 'endpoint' and 'long_slug' by default are rendered
- 'url' is always redirect
- 'string' and 'template' are always rendered
"""
app = current_app
aliases_map = app.config.get("ALIASES_MAP")
if aliases_map and request.path in aliases_map:
alias = aliases_map[request.path]
status = alias.get("status", 200)
if alias["alias_type"] == "endpoint":
endpoint = alias["to"]
if alias.get("action") == "redirect":
return redirect(url_for(endpoint, **request.args))
else: # render
return app.process_response(app.make_response(app.view_functions[endpoint]()))
elif alias["alias_type"] == "long_slug":
long_slug = alias["to"]
if alias.get("action") == "redirect":
return redirect(long_slug) # pass request.args ?
else: # render
endpoint = route_from(long_slug)[0]
return app.process_response(app.make_response(app.view_functions[endpoint]()))
elif alias["alias_type"] == "url":
return redirect(alias["to"])
elif alias["alias_type"] == "string":
return render_template_string(alias["to"]), status
elif alias["alias_type"] == "template":
return render_template(alias["to"]), status
示例12: get
def get(self):
"""
Fixme: Should include extra paths, fixed paths
config based paths, static paths
"""
return render_template(
'sitemap.xml',
contents=self.get_contents(),
channels=self.get_channels()
)
示例13: get
def get(self):
user = get_current_user()
context = {}
for link in user.links:
context[link.icon] = link.link
return self.needs_login() or render_template(
'accounts/profile_edit.html',
form=self.form(instance=user),
**context
)
示例14: __call__
def __call__(self, *args, **kwargs):
html = super(PrepopulatedText, self).__call__(*args, **kwargs)
slave = args[0].id
if self.master:
html += render_template(
'admin/custom/prepopulated.html',
theme=current_app.config.get('ADMIN_THEME', 'cosmo'),
master=self.master,
slave=slave
)
return html
示例15: render
def render(self, template, **kwargs):
# Store self as admin_view
kwargs['admin_view'] = self
kwargs['admin_base_template'] = self.admin.base_template
# Provide i18n support even if flask-babel is not installed or enabled.
kwargs['_gettext'] = gettext
kwargs['_ngettext'] = ngettext
kwargs['h'] = h
# Contribute extra arguments
kwargs.update(self._template_args)
return render_template(template, **kwargs)