FLASK THE ERROR TEST of: login_required() decorator with argument

Surprise mother f**ker!

I write the code are same as internet! But I will get error like:

AssertionError: 
    View function mapping is overwriting an existing endpoint function: api.deco

I try my best to find the solution..but no one have the problem same as me!
Bloody hell!!!!!!!!!

And I am start to the source code of flask
and try to know how the FLASK Blueprint work..THIS GIVE ME HELP


But I know one thing soon,
one thing:

  • My decorator is not bad, I need to not why I get a ERROR

So I change the code of FLASK…..
Don't punch me..
I have to change the add_url_rule to this:

    def add_url_rule(self, rule, endpoint=None, view_func=None, **options):
        """A helper method to register a rule (and optionally a view function)
        to the application.  The endpoint is automatically prefixed with the
        blueprint's name.
        """
        print(self.app.view_functions) # this is my code
        if self.url_prefix:
            rule = self.url_prefix + rule
        options.setdefault('subdomain', self.subdomain)
        if endpoint is None:
            endpoint = _endpoint_from_view_func(view_func)
        defaults = self.url_defaults
        if 'defaults' in options:
            defaults = dict(defaults, **options.pop('defaults'))
        self.app.add_url_rule(rule, '%s.%s' % (self.blueprint.name, endpoint),
                              view_func, defaults=defaults, **options)

So I can get the information of view_functions

And I got this:

{'static': <bound method _PackageBoundObject.send_static_file of <Flask 'work_muxixyz_app'>>}
{'static': <bound method _PackageBoundObject.send_static_file of <Flask 'work_muxixyz_app'>>, 'api.login': <function login at 0x7f62ea9a7488>}
{'static': <bound method _PackageBoundObject.send_static_file of <Flask 'work_muxixyz_app'>>, 'api.login': <function login at 0x7f62ea9a7488>, 'api.NewGroup': <function new_group at 0x7f62ea7c8598>}
...
... ===> See the tail of code===>
...
{'static': <bound method _PackageBoundObject.send_static_file of <Flask 'work_muxixyz_app'>>, 'api.login': <function login at 0x7f62ea9a7488>, 'api.NewGroup': <function new_group at 0x7f62ea7c8598>, 'api.GroupDelete': <function group_delete at 0x7f62ea7c8730>, 'api.GroupUserList': <function group_user_list at 0x7f62ea7c88c8>, 'api.GroupList': <function group_list at 0x7f62ea7c8a60>, 'api.ProjectUserList': <function project_user_list at 0x7f62ea7c8bf8>, 'api.UserProjectList': <function user_project_list at 0x7f62ea7c8d90>, 'api.User2bMember': <function user_2b_member at 0x7f62ea7c8f28>, 'api.AddAdmin': <function add_admin at 0x7f62ea7ca158>, 'api.ManageProject': <function manage_project at 0x7f62ea7ca2f0>, 'api.ManageGroup': <function manage_group at 0x7f62ea7ca488>, 'api.SetRole': <function set_role at 0x7f62ea7ca620>, 'api.1': <function two at 0x7f62ea7ca7b8>}
{'static': <bound method _PackageBoundObject.send_static_file of <Flask 'work_muxixyz_app'>>, 'api.login': <function login at 0x7f62ea9a7488>, 'api.NewGroup': <function new_group at 0x7f62ea7c8598>, 'api.GroupDelete': <function group_delete at 0x7f62ea7c8730>, 'api.GroupUserList': <function group_user_list at 0x7f62ea7c88c8>, 'api.GroupList': <function group_list at 0x7f62ea7c8a60>, 'api.ProjectUserList': <function project_user_list at 0x7f62ea7c8bf8>, 'api.UserProjectList': <function user_project_list at 0x7f62ea7c8d90>, 'api.User2bMember': <function user_2b_member at 0x7f62ea7c8f28>, 'api.AddAdmin': <function add_admin at 0x7f62ea7ca158>, 'api.ManageProject': <function manage_project at 0x7f62ea7ca2f0>, 'api.ManageGroup': <function manage_group at 0x7f62ea7ca488>, 'api.SetRole': <function set_role at 0x7f62ea7ca620>, 'api.1': <function two at 0x7f62ea7ca7b8>, 'api.two': <function login_required.<locals>.deco at 0x7f62ea7caa60>}

And you should notice that: these print are before ERROR, so you know that:

  • function add_url_rule() add all the API to the view_functions,
  • and then?
  • It try to add the last API’s decorator to this map, even more!!!
  • Unless….
  • My computer have itself mention……
  • ahhhhhhhhhh!!!!!

F**K OFF!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值