在shub部署项目上设置变量 [英] Set variable on shub deploy project
问题描述
我正在尝试设置scrapy设置,以与本地以及scrapinghub上的测试和生产环境一起使用. 而且我想知道是否有任何方法可以在shub deploy上设置此变量(例如,如下所示):
I'm trying to setup scrapy settings to work with test and production environment on local and also on scrapinghub. And I would like to know if there is any way to set this variable (for example as the following) on shub deploy:
然后在settings.py:
And then at settings.py:
if env == "test":
var1 = some_ip
var2 = username
elif env == "prod":
var1 = some_ip
var2 = username
或者...也许有更清洁的方法吗?
Or... maybe there is a cleaner way to this?
感谢您的阅读!
PS:我想根据蜘蛛/项目所在的环境自动进行设置,而不是手动更改变量.
PS: I want to automate the settings depending of the environment where is the spider/project located instead of changing the variables manually.
推荐答案
最后,我按照以下步骤解决了我的问题:
Finally, I solved my problem following these steps:
- 实施此示例.
所以现在我的设置如下:
So now my settings look like this:
- 然后我的
__init__.py
看起来像这样:
- And then my
__init__.py
look like this:
- 接下来,将
_environment.py
修改为以下内容:
- Next, modified
_environment.py
as the following:
希望我能对您有所帮助!
I hope I have been helpful!
PS:请记住,您需要在scrapinghub上有两个项目,一个用于生产,一个用于测试,要执行此操作,还需要从以下相同的项目中进行部署:
PS: Remember that you need to have two projects on scrapinghub, one for production and one for testing to do this, also you need to deploy from the same project as the following:
然后,您只需要(参考):
-
shub deploy test
部署进行测试. -
shub deploy prod
部署到生产环境. -
shub deploy
部署进行测试.
shub deploy test
Deploys to test.shub deploy prod
Deploys to production.shub deploy
Deploys to test.
这篇关于在shub部署项目上设置变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!