How to import Scrapy item keys in the correct order?

前端 未结 2 2002
小蘑菇
小蘑菇 2021-01-24 06:09

I am importing the Scrapy item keys from items.py, into pipelines.py. The problem is that the order of the imported items are differe

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-24 06:28

    A simple fix is to define keys() method in your Item class:

    class MyItem(Item):
        foo = Field()
        bar = Field()
        gar = Field()
        cha = Field()
    
        def keys(self):
            # in your preferred order
            return ['cha', 'gar','bar','foo']
    

提交回复
热议问题