Run Pylons controller as separate app?

前端 未结 2 1919
走了就别回头了
走了就别回头了 2021-02-14 05:33

I have a Pylons app where I would like to move some of the logic to a separate batch process. I\'ve been running it under the main app for testing, but it is going to be doing

2条回答
  •  孤独总比滥情好
    2021-02-14 06:05

    If you want to load parts of a Pylons app, such as the models from outside Pylons, load the Pylons app in the script first:

    from paste.deploy import appconfig
    from pylons import config
    
    from YOURPROJ.config.environment import load_environment
    
    conf = appconfig('config:development.ini', relative_to='.')
    load_environment(conf.global_conf, conf.local_conf)
    

    That will load the Pylons app, which sets up most of the state so that you can proceed to use the SQLAlchemy models and Session to work with the database.

    Note that if your code is using the pylons globals such as request/response/etc then that won't work since they require a request to be in progress to exist.

提交回复
热议问题