• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python jinja2.get_jinja2函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中webapp2_extras.jinja2.get_jinja2函数的典型用法代码示例。如果您正苦于以下问题:Python get_jinja2函数的具体用法?Python get_jinja2怎么用?Python get_jinja2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_jinja2函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: handle_error

def handle_error(request, response, exception):
    c = {"exception": str(exception), "url": request.url}

    if config.send_mail_developer is not False:
        # send email
        subject = config.app_name + " error."
        email_body_path = "emails/error.txt"
        message = "This error was looking for you: " + c["exception"] + " from " + c["url"]

        if c["exception"] is not "Error saving Email Log in datastore":
            template_val = {"app_name": config.app_name, "message": message}

            email_body = jinja2.get_jinja2(factory=jinja2_factory, app=webapp2.get_app()).render_template(
                email_body_path, **template_val
            )
            email_url = webapp2.uri_for("taskqueue-send-email")

            for dev in config.DEVELOPERS:
                taskqueue.add(
                    url=email_url,
                    params={"to": dev[1], "subject": subject, "body": email_body, "sender": config.contact_sender},
                )

    status_int = hasattr(exception, "status_int") and exception.status_int or 500
    template = config.error_templates[status_int]
    t = jinja2.get_jinja2(factory=jinja2_factory, app=webapp2.get_app()).render_template(template, **c)
    logging.error(str(status_int) + " - " + str(exception))
    response.write(t)
    response.set_status(status_int)
开发者ID:berndsi,项目名称:gae-boilerplate,代码行数:29,代码来源:basehandler.py


示例2: handle_error

def handle_error(request, response, exception):
    c = {
        'exception': str(exception),
        'url': request.url,
        }

    if config.send_mail_developer is not False:
        # send email
        subject         = config.app_name + " error."
        email_body_path = "emails/error.txt"
        message         = 'This error was looking for you: ' + c['exception'] + ' from ' + c['url']

        if c['exception'] is not 'Error saving Email Log in datastore':
            template_val = {
                "app_name"  : config.app_name,
                "message"   : message,
                }

            email_body = jinja2.get_jinja2(factory=jinja2_factory, app=webapp2.get_app()).render_template(email_body_path, **template_val)
            email_url = webapp2.uri_for('taskqueue-send-email')

            for dev in config.DEVELOPERS:
                taskqueue.add(url = email_url, params={
                    'to':       dev[1],
                    'subject' : subject,
                    'body' :    email_body,
                    'sender' :  config.contact_sender,
                    })

    status_int = hasattr(exception, 'status_int') and exception.status_int or 500
    template = config.error_templates[status_int]
    t = jinja2.get_jinja2(factory=jinja2_factory, app=webapp2.get_app()).render_template(template, **c)
    logging.error(str(status_int) + " - " + str(exception))
    response.write(t)
    response.set_status(status_int)
开发者ID:acidlabs,项目名称:gae-boilerplate,代码行数:35,代码来源:basehandler.py


示例3: handle_error

def handle_error(request, response, exception):
    exc_type, exc_value, exc_tb = sys.exc_info()

    c = {"exception": str(exception), "url": request.url}

    if request.app.config.get("send_mail_developer") is not False:
        # send email
        subject = "[{}] ERROR {}".format(
            request.app.config.get("environment").upper(), request.app.config.get("app_name")
        )

        lines = traceback.format_exception(exc_type, exc_value, exc_tb)

        message = (
            "<strong>Type:</strong> "
            + exc_type.__name__
            + "<br />"
            + "<strong>Description:</strong> "
            + c["exception"]
            + "<br />"
            + "<strong>URL:</strong> "
            + c["url"]
            + "<br />"
            + "<strong>Traceback:</strong> <br />"
            + "<br />".join(lines)
        )

        email_body_path = "emails/error.txt"
        if c["exception"] is not "Error saving Email Log in datastore":
            template_val = {"app_name": request.app.config.get("app_name"), "message": message}

            email_body = jinja2.get_jinja2(factory=jinja2_factory, app=webapp2.get_app()).render_template(
                email_body_path, **template_val
            )
            email_url = webapp2.uri_for("taskqueue-send-email")

            for dev in request.app.config.get("developers"):
                taskqueue.add(
                    url=email_url,
                    params={
                        "to": dev[1],
                        "subject": subject,
                        "body": email_body,
                        "sender": request.app.config.get("contact_sender"),
                    },
                )

    status_int = hasattr(exception, "status_int") and exception.status_int or 500
    template = request.app.config.get("error_templates")[status_int]
    t = jinja2.get_jinja2(factory=jinja2_factory, app=webapp2.get_app()).render_template(template, **c)
    logging.error(str(status_int) + " - " + str(exception))
    response.write(t)
    response.set_status(status_int)
开发者ID:fccoelho,项目名称:epigrassgae,代码行数:53,代码来源:basehandler.py


示例4: __init__

	def __init__(self, request, response):
		self.initialize( request, response )

		# ログインしてなかったらログイン画面に飛ばす
		if users.is_current_user_admin() == False:
			self.redirect( users.create_login_url(self.request.uri) )
			return

		# サイドバー HTML を jinja2 の globals に登録
		sidebar_str = jinja2.get_jinja2().render_template( 'sidebar.html', **{
			"customObjects": config.CUSTOM_OBJECTS,
		})
		jinja2.get_jinja2().environment.globals["sidebar"] = sidebar_str
开发者ID:noughts,项目名称:openfish,代码行数:13,代码来源:admin.py


示例5: handle_500

def handle_500(request, response, exception):
    t = jinja2.get_jinja2(app=application).render_template(
        'errors/500.html', **{
            'exception': exception.message,
#            'application': Config.get('application'),
        })
    response.write(t)
开发者ID:scotch,项目名称:aestarter,代码行数:7,代码来源:main.py


示例6: jinja2

 def jinja2(self):
     from webapp2_extras import jinja2
     # Returns a Jinja2 renderer cached in the app registry.
     j = jinja2.get_jinja2(app=self.app)
     j.environment.variable_start_string = '@{'
     j.environment.variable_end_string = '}@'
     return j
开发者ID:fredrikbonander,项目名称:channel-example,代码行数:7,代码来源:main.py


示例7: jinja2

    def jinja2(self):
        # Returns a Jinja2 renderer cached in the app registry.
        jinja2_obj = jinja2.get_jinja2(app=self.app)

        jinja2_obj.environment.filters['format_currency'] = self.format_currency
        
        return jinja2_obj
开发者ID:LeetCoinTeam,项目名称:lc_api_examples,代码行数:7,代码来源:handlers.py


示例8: handle_error

def handle_error(request, response, exception):
    c = { 'exception': str(exception) }
    status_int = hasattr(exception, 'status_int') and exception.status_int or 500
    template = config.error_templates[status_int]
    t = jinja2.get_jinja2(app=app).render_template(template, **c)
    response.write(t)
    response.set_status(status_int)
开发者ID:ulisescab,项目名称:gae-boilerplate,代码行数:7,代码来源:main.py


示例9: render

  def render(self, name, value, attrs=None):
    # TODO: handle other data types
    # this currently only works for issubclass(self.property.item_type, db.Key)
    objects = []
    object_classes = self.object_classes

    keys = value or []
    for key in keys:
      if not key:
        continue
      # Turn string keys into Key objects
      if isinstance(key, basestring):
        key = db.Key(key)
      obj = db.get(key)
      objects.append((key, obj))
      object_classes[obj.__class__.__name__] = obj.__class__

    final_attrs = self.build_attrs(attrs, name=name)
    flat_attrs = flatatt(final_attrs)

    from .handlers import AdminHandler
    handler = AdminHandler()

    from webapp2_extras import jinja2

    return jinja2.get_jinja2().render_template(
      'widgets/ajax_list_property.html',
      flat_attrs=flat_attrs,
      objects=objects,
      object_classes=object_classes,
      get_item_edit_url=partial(self._get_item_edit_url, handler=handler),
      name=name,
      paged_selector=partial(self._paged_selector, handler=handler),
    )
开发者ID:BRupholdt,项目名称:appengine-admin,代码行数:34,代码来源:admin_widgets.py


示例10: test_set_jinja2

 def test_set_jinja2(self):
     app = webapp2.WSGIApplication()
     self.assertEqual(len(app.registry), 0)
     jinja2.set_jinja2(jinja2.Jinja2(app), app=app)
     self.assertEqual(len(app.registry), 1)
     j = jinja2.get_jinja2(app=app)
     self.assertTrue(isinstance(j, jinja2.Jinja2))
开发者ID:GoogleCloudPlatform,项目名称:webapp2,代码行数:7,代码来源:extras_jinja2_test.py


示例11: jinja2

    def jinja2(self):
        """Cached property holding a Jinja2 instance.

        Returns:
            A Jinja2 object for the current app.
        """
        return jinja2.get_jinja2(app=self.app)
开发者ID:mezzohead,项目名称:appengine-sharded-counters-python,代码行数:7,代码来源:main.py


示例12: handle_404

def handle_404(request, response, exception):
    logging.exception(exception)
    
    renderer = jinja2.get_jinja2()
    response.write(renderer.render_template('errors/404.html'))
    
    response.set_status(404)
开发者ID:gustavosaume,项目名称:engineauth-boilerplate,代码行数:7,代码来源:error_handlers.py


示例13: jinja2

 def jinja2(self):
     def factory(app):
         config = jinja2.default_config
         config['template_path'] = app.config['template_path']
         config['environment_args']['line_statement_prefix'] = '%'
         return jinja2.Jinja2(app, config)
     return jinja2.get_jinja2(factory=factory, app=self.app)
开发者ID:brotchie,项目名称:redsapp,代码行数:7,代码来源:base.py


示例14: list

	def list( self, class_name ):
		# 文字列からモデルクラス、エンティティ取得
		classPath_str = "models."+ class_name.capitalize()
		klass = webapp2.import_string( classPath_str )

		# entities = klass.query( klass.is_deleted==False ).order( -klass.created_at )
		entities = klass.query()


		entities_json = []
		for entity in entities:
			entities_json.append( entity.toDict() )


		# プロパティ情報を dict に入れる
		props = []
		for prop in klass.__dict__["_properties"]:
			props.append({
				"name": prop,
				"className": getattr(klass,prop).__class__.__name__,
			})
		# logging.info( props )

		res = jinja2.get_jinja2().render_template( 'admin/list.html', **{
			"entities": entities,
			"entities_json": json.encode( entities_json ),
			"props": props,
			"class_name": class_name,
		})
		self.response.out.write( res )
开发者ID:noughts,项目名称:openfish,代码行数:30,代码来源:admin.py


示例15: ErrorHandler

def ErrorHandler(request, response, exception, code):
    """A webapp2 implementation of error_handler."""
    logging.info('ErrorHandler code %s' % code)
    logging.info('Exception: %s' % exception)

    response.set_status(code)
    response.headers['Access-Control-Allow-Origin'] = \
        request.headers.get('Origin', '*')
    response.headers['Access-Control-Allow-Methods'] = \
        'GET, POST, OPTIONS, PUT'
    response.headers['Access-Control-Allow-Credentials'] = 'true'
    response.headers['Access-Control-Allow-Headers'] = \
        'Content-Type,X-Requested-With'

    # Default UA string is for unit tests.
    user_agent_string = request.headers.get(
        'USER_AGENT', settings.USER_AGENT)

    ua_dict = user_agent_parser.Parse(user_agent_string)
    logging.info('UA: %s' % ua_dict)
    tpl_data = {
        'error_code': code,
        'error_code_text': httplib.responses[code],
        'error_message': exception,
        'user_agent': ua_dict
    }
    jinja2_instance = jinja2.get_jinja2()
    rendered = jinja2_instance.render_template('error.html', **tpl_data)
    response.write(rendered)
开发者ID:elsigh,项目名称:levels,代码行数:29,代码来源:web_request_handler.py


示例16: handler

 def handler(request, response, exception):
     logging.exception(exception)
     app = webapp2.get_app()
     j = jinja2.get_jinja2(app=app)
     rv = j.render_template("errors/" + str(code) + ".html")
     response.write(rv)
     response.set_status(code)
开发者ID:shonenada,项目名称:shonenada.com,代码行数:7,代码来源:exception.py


示例17: error

def error(request, response, exception):
    logging.exception(exception)
    params = {
        'error': exception
    }
    jinja = jinja2.get_jinja2()
    response.write(jinja.render_template('error.html', **params))
开发者ID:goldinitp,项目名称:goldi-io,代码行数:7,代码来源:prod_router.py


示例18: jinja2

    def jinja2(self):
        jinja2.default_config['template_path'] = configuration.VIEW_PATH

        jinja2.default_config['globals'] = {
            'get_route': get_route
        }

        return jinja2.get_jinja2(app=self.app)
开发者ID:tombatron,项目名称:tombatron-com,代码行数:8,代码来源:controllers.py


示例19: jinja2

 def jinja2(self):
     """ xxx todo """
     j = jinja2.get_jinja2(app=self.app)
     # not good.
     j.environment.globals.update({
         'uri_for': self.uri_for,
         })
     return j
开发者ID:hartym,项目名称:rdc.web,代码行数:8,代码来源:handler.py


示例20: handle_error

def handle_error(request, response, exception):
    c = { 'exception': str(exception) }
    status_int = hasattr(exception, 'status_int') and exception.status_int or 500
    template = config.error_templates[status_int]
    t = jinja2.get_jinja2(factory=jinja2_factory, app=webapp2.get_app()).render_template(template, **c)
    logging.error(str(status_int) + " - " + str(exception))
    response.write(t)
    response.set_status(status_int)
开发者ID:mfkasim91,项目名称:gae-boilerplate,代码行数:8,代码来源:basehandler.py



注:本文中的webapp2_extras.jinja2.get_jinja2函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python json.decode函数代码示例发布时间:2022-05-26
下一篇:
Python i18n.ngettext函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap