Run Pylons controller as separate app?

前端 未结 2 1917
走了就别回头了
走了就别回头了 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 05:59

    I'm redacting my response and upvoting the other answer by Ben Bangert, as it's the correct one. I answered and have since learned the correct way (mentioned below). If you really want to, check out the history of this answer to see the wrong (but working) solution I originally proposed.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题