当前位置: 首页>>代码示例>>Python>>正文


Python views.View方法代码示例

本文整理汇总了Python中flask.views.View方法的典型用法代码示例。如果您正苦于以下问题:Python views.View方法的具体用法?Python views.View怎么用?Python views.View使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flask.views的用法示例。


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

示例1: route_as_view

# 需要导入模块: from flask import views [as 别名]
# 或者: from flask.views import View [as 别名]
def route_as_view(cls, app, name, rules, *class_args, **class_kwargs):
        """ Register the view with an URL route
        :param app: Flask application
        :type app: flask.Flask|flask.Blueprint
        :param name: Unique view name
        :type name: str
        :param rules: List of route rules to use
        :type rules: Iterable[str|werkzeug.routing.Rule]
        :param class_args: Args to pass to object constructor
        :param class_kwargs: KwArgs to pass to object constructor
        :return: View callable
        :rtype: Callable
        """
        view = super(MethodView, cls).as_view(name, *class_args, **class_kwargs)
        for rule in rules:
            app.add_url_rule(rule, view_func=view)
        return view 
开发者ID:kolypto,项目名称:py-flask-jsontools,代码行数:19,代码来源:views.py

示例2: test_class_based_views

# 需要导入模块: from flask import views [as 别名]
# 或者: from flask.views import View [as 别名]
def test_class_based_views(sentry_init, app, capture_events):
    sentry_init(integrations=[flask_sentry.FlaskIntegration()])
    events = capture_events()

    @app.route("/")
    class HelloClass(View):
        def dispatch_request(self):
            capture_message("hi")
            return "ok"

    app.add_url_rule("/hello-class/", view_func=HelloClass.as_view("hello_class"))

    with app.test_client() as client:
        response = client.get("/hello-class/")
        assert response.status_code == 200

    (event,) = events

    assert event["message"] == "hi"
    assert event["transaction"] == "hello_class" 
开发者ID:getsentry,项目名称:sentry-python,代码行数:22,代码来源:test_flask.py

示例3: test_requires_works_as_cbv_decorator

# 需要导入模块: from flask import views [as 别名]
# 或者: from flask.views import View [as 别名]
def test_requires_works_as_cbv_decorator(app, ismember, guest):
    class IsMemberView(View):
        decorators = [requires(ismember)]

    Allows(app=app, identity_loader=lambda: guest)

    with pytest.raises(Forbidden):
        with app.app_context():
            IsMemberView.as_view("memberonly")() 
开发者ID:justanr,项目名称:flask-allows,代码行数:11,代码来源:test_views.py

示例4: handle_500

# 需要导入模块: from flask import views [as 别名]
# 或者: from flask.views import View [as 别名]
def handle_500(e):
    return '500', 500


# Registering a flask.views.View class as an endpoint 
开发者ID:DataDog,项目名称:trace-examples,代码行数:7,代码来源:app.py

示例5: update_g

# 需要导入模块: from flask import views [as 别名]
# 或者: from flask.views import View [as 别名]
def update_g(self):
        # g lifetime: every single request
        # Note that use inject_variable() in View class would cause memory leak, issue #14
        g.IS_MOBILE = self.IS_MOBILE
        g.url_jobs_list = [url_for('jobs', node=node, ui=self.UI)
                           for node in range(1, self.SCRAPYD_SERVERS_AMOUNT + 1)]
        g.multinode = ('<label title="multinode">'
                       '<svg class="icon" aria-hidden="true"><use xlink:href="#icon-servers"></use></svg>'
                       '</label>')
        # For base.html
        if not self.USE_MOBILEUI:
            g.url_daemonstatus = url_for('api', node=self.node, opt='daemonstatus')
            g.url_menu_servers = url_for('servers', node=self.node)
            g.url_menu_jobs = url_for('jobs', node=self.node)
            g.url_menu_nodereports = url_for('nodereports', node=self.node)
            g.url_menu_clusterreports = url_for('clusterreports', node=self.node)
            g.url_menu_tasks = url_for('tasks', node=self.node)
            g.url_menu_deploy = url_for('deploy', node=self.node)
            g.url_menu_schedule = url_for('schedule', node=self.node)
            g.url_menu_projects = url_for('projects', node=self.node)
            g.url_menu_logs = url_for('logs', node=self.node)
            g.url_menu_items = url_for('items', node=self.node)
            g.url_menu_sendtext = url_for('sendtext', node=self.node)
            g.url_menu_parse = url_for('parse.upload', node=self.node)
            g.url_menu_settings = url_for('settings', node=self.node)
            g.url_menu_mobileui = url_for('index', node=self.node, ui='mobile')
            g.scheduler_state_paused = self.scheduler.state == STATE_PAUSED and self.any_running_apscheduler_jobs
            g.scheduler_state_running = self.scheduler.state == STATE_RUNNING and self.any_running_apscheduler_jobs

    # Issue#48 [PY2] UnicodeDecodeError raised when there are some files with illegal filenames in `SCRAPY_PROJECTS_DIR`
    # https://stackoverflow.com/questions/21772271/unicodedecodeerror-when-performing-os-walk
    # https://xuanwo.io/2018/04/01/python-os-walk/
    # Tested in Ubuntu:
    # touch $(echo -e "\x8b\x8bFile")
    # mkdir $(echo -e "\x8b\x8bFolder") 
开发者ID:my8100,项目名称:scrapydweb,代码行数:37,代码来源:baseview.py

示例6: test_pluggable_views

# 需要导入模块: from flask import views [as 别名]
# 或者: from flask.views import View [as 别名]
def test_pluggable_views(extension_factory):
    app, limiter = extension_factory(default_limits=["1/hour"])

    class Va(View):
        methods = ['GET', 'POST']
        decorators = [limiter.limit("2/second")]

        def dispatch_request(self):
            return request.method.lower()

    class Vb(View):
        methods = ['GET']
        decorators = [limiter.limit("1/second, 3/minute")]

        def dispatch_request(self):
            return request.method.lower()

    class Vc(View):
        methods = ['GET']

        def dispatch_request(self):
            return request.method.lower()

    app.add_url_rule("/a", view_func=Va.as_view("a"))
    app.add_url_rule("/b", view_func=Vb.as_view("b"))
    app.add_url_rule("/c", view_func=Vc.as_view("c"))
    with hiro.Timeline().freeze() as timeline:
        with app.test_client() as cli:
            assert 200 == cli.get("/a").status_code
            assert 200 == cli.get("/a").status_code
            assert 429 == cli.post("/a").status_code
            assert 200 == cli.get("/b").status_code
            timeline.forward(1)
            assert 200 == cli.get("/b").status_code
            timeline.forward(1)
            assert 200 == cli.get("/b").status_code
            timeline.forward(1)
            assert 429 == cli.get("/b").status_code
            assert 200 == cli.get("/c").status_code
            assert 429 == cli.get("/c").status_code 
开发者ID:alisaifee,项目名称:flask-limiter,代码行数:42,代码来源:test_views.py


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