Re: blueprints register problems.
- From:
- Spacelee
- Date:
- 2012-03-27 @ 09:26
sorry, I got it, it's this line 's problem
@configs.route('/', method=['GET', 'POST'])
which should be
@configs.route('/', methods=['GET', 'POST'])
On Tue, Mar 27, 2012 at 5:22 PM, Spacelee <fjctlzy@gmail.com> wrote:
> I use this line in the main function:
> app.register_blueprint(examples, url_prefix='/examples')
> app.register_blueprint(configs, url_prefix='/configs')
>
> and the configs is like this:
> from __future__ import with_statement
>
> from flask import Flask, request, jsonify, Blueprint
>
> #from applications.models.config.config_model import ConfigModel
> #from applications.helpers.common import fail, success
>
> configs = Blueprint('configs', __name__)
>
> class Configs:
>
> def __init__(self):
> pass#self.config_model = ConfigModel()
>
> @configs.route('/', method=['GET', 'POST'])
> def get_config_by_cluster_name(self):
> cluster_name = request.args.get('cluster_name', None)
> if cluster_name:
> result = self.config_model.get_config_by_cluster_name(cluster_name)
> #return jsonify(success(result))
> else:
> pass#return jsonify(fail("cluster_name is empty"))
>
>
>
> and when I start the main function, it said:
> Traceback (most recent call last):
> File "main.py", line 57, in <module>
> app.register_blueprint(configs, url_prefix='/configs')
> File
> "/usr/local/lib/python2.7/dist-packages/Flask-0.8-py2.7.egg/flask/app.py",
> line 63, in wrapper_func
> return f(self, *args, **kwargs)
> File
> "/usr/local/lib/python2.7/dist-packages/Flask-0.8-py2.7.egg/flask/app.py",
> line 809, in register_blueprint
> blueprint.register(self, options, first_registration)
> File
>
"/usr/local/lib/python2.7/dist-packages/Flask-0.8-py2.7.egg/flask/blueprints.py",
> line 153, in register
> deferred(state)
> File
>
"/usr/local/lib/python2.7/dist-packages/Flask-0.8-py2.7.egg/flask/blueprints.py",
> line 172, in <lambda>
> s.add_url_rule(rule, endpoint, view_func, **options))
> File
>
"/usr/local/lib/python2.7/dist-packages/Flask-0.8-py2.7.egg/flask/blueprints.py",
> line 76, in add_url_rule
> view_func, defaults=defaults, **options)
> File
> "/usr/local/lib/python2.7/dist-packages/Flask-0.8-py2.7.egg/flask/app.py",
> line 63, in wrapper_func
> return f(self, *args, **kwargs)
> File
> "/usr/local/lib/python2.7/dist-packages/Flask-0.8-py2.7.egg/flask/app.py",
> line 889, in add_url_rule
> rule = self.url_rule_class(rule, methods=methods, **options)
> TypeError: __init__() got an unexpected keyword argument 'method'
>
>
>
>
> Another example controller is OK, it looks like this:
> from __future__ import with_statement
>
> from flask import Flask, request, session, g, redirect, url_for, jsonify,
> Blueprint
> from applications.models.examples import ExampleModel
>
> examples = Blueprint('examples', __name__)
>
> class Examples:
>
> def __init__(self):
> pass
> @examples.route('/')
> @examples.route('/login', methods=['GET', 'POST'])
> def login():
> return 'login form'
>
> @examples.route('/user/create')
> def insert_user():
> name = request.args.get('name', '')
> example_model = ExampleModel()
> example_model.insert_name(name)
> return jsonify(example_model.get_name())
>
> --
> *Space Lee*
>
>
--
*Space Lee*