Search code examples
pyramid

How to access the current config in a view handler?


I want to use a config method ('absolute_asset_spec') in a view handler. How do I get the config object to invoke it on?

I've seen talk of a Config() method but where is it defined? Searching for it is, shall we say, problematic :)


Solution

  • Is request.registry.settings what you are looking for?

    More details here:

    Pyramid and .ini configuration

    Or you were talking about a method. You want to access a method in every request?

    def some_method():
       return 'stuff you want'
    
    # in your main function
    config.add_request_method(some_method, 'stuff', reify=True)
    
    # in a view
    foo = request.stuff