Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configurationファイルパスを外から指定できない #10

Closed
dodo5522 opened this issue Jun 27, 2017 · 1 comment
Closed

configurationファイルパスを外から指定できない #10

dodo5522 opened this issue Jun 27, 2017 · 1 comment

Comments

@dodo5522
Copy link
Owner

dodo5522 commented Jun 27, 2017

gunicornでアプリ起動する際に引数でパラメータ渡し可能。

In your application module you can do something like this:

def load_app(cfg_file):
    cfg = load_app_config(cfg_file)
    return my_app(cfg)
And then you start your app like such:

$ gunicorn 'webapp:load_app("/path/to/my_config.ini")'

Viewクラスにもas_viewメソッド経由で渡せる。

Signature: MethodView.as_view(name, *class_args, **class_kwargs)
Source:   
    @classmethod
    def as_view(cls, name, *class_args, **class_kwargs):
        """Converts the class into an actual view function that can be used
        with the routing system.  Internally this generates a function on the
        fly which will instantiate the :class:`View` on each request and call
        the :meth:`dispatch_request` method on it.

        The arguments passed to :meth:`as_view` are forwarded to the
        constructor of the class.
        """
        def view(*args, **kwargs):
            self = view.view_class(*class_args, **class_kwargs)
            return self.dispatch_request(*args, **kwargs)

        if cls.decorators:
            view.__name__ = name
            view.__module__ = cls.__module__
            for decorator in cls.decorators:
                view = decorator(view)

        # We attach the view class to the view function for two reasons:
        # first of all it allows us to easily figure out what class-based
        # view this thing came from, secondly it's also used for instantiating
        # the view class so you can actually replace it with something else
        # for testing purposes and debugging.
        view.view_class = cls
        view.__name__ = name
        view.__doc__ = cls.__doc__
        view.__module__ = cls.__module__
        view.methods = cls.methods
        return view
File:      ~/.anyenv/envs/pyenv/versions/3.5.1/envs/dev_necco/lib/python3.5/site-packages/flask/views.py
Type:      method
@dodo5522 dodo5522 changed the title configオブジェクトをViewクラス他全てに渡す configurationファイルパスを外から指定できない Jun 27, 2017
@dodo5522
Copy link
Owner Author

できた。

こんな感じ。

$ gunicorn 'necco.__main__:create_application_for_debug("/etc/necco/necco.ini")'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant