开发者

get_or_create() takes exactly 1 argument (2 given)

开发者 https://www.devze.com 2023-03-29 01:30 出处:网络
Last time I checked, (h) one argument: for entry in f[\'entries\']: h = {开发者_StackOverflow中文版\'feed\':self, \'link\': entry[\'link\'],\'title\':entry[\'title\'],

Last time I checked, (h) one argument:

for entry in f['entries']:
    h = {开发者_StackOverflow中文版'feed':self, 'link': entry['link'],'title':entry['title'],
         'summary':entry['summary'],
         'updated_at':datetime.fromtimestamp(mktime(entry['updated_parsed']))}

    en = Entry.objects.get_or_create(h)

This code is failing with the error in the title. What can I check for?


get_or_create takes keyword arguments only. If the arguments are in a dict, you can call it with:

en = Entry.objects.get_or_create(**h)

Or you can put the keyword arguments directly:

en = Entry.objects.get_or_create(name=value, ....)

The reason the error message told you that you supplied two arguments is that there is an implicit self parameter passed to the function.

0

精彩评论

暂无评论...
验证码 换一张
取 消