问题描述
django应用程序中我的一个模块中的类存在使用超级...构造自身的问题.
A class in one of my modules in my django application has a problem constructing itself using super...
class LinkshareExternalAffiliateProperties(AffiliateExternalProperties):
def __init__(self, aggregator_affiliate_id, account_username, account_password, api_token):
super(LinkshareExternalAffiliateProperties, self).__init__(aggregator_affiliate_id)
self.account_username = account_username
self.account_password = account_password
self.api_token = api_token
class AffiliateExternalProperties(object):
def __getattribute__(self, attr):
sources = super(AffiliateExternalProperties, self).__getattribute__('__sources__')
if attr in sources:
return self.get(attr)
else:
return super(AffiliateExternalProperties, self).__getattribute__(attr)
调用代码时出现错误:super()参数1必须为类型,而不是无LinkshareExternalAffiliateProperties如何在此处评估为无"?这是这个新实例的类!同一模块中的其他类目前也无法使用.
When the code is called I get an error: super() argument 1 must be type, not NoneHow does LinkshareExternalAffiliateProperties evaluate to None right here? Its the class of this new instance!! Other classes in the same module are also unavailable at this time.
一些有趣的事情(这整个事情都是令人费解的,但整个故事的某些部分可能是造成问题的原因...):
SOME THINGS OF INTEREST (This whole thing is convoluted but some part of the whole story could be what is creating the problem...):
class Aggregator(models.Model):
foo = columns
@property
def proxy(self):
if self.name == 'Linkshare':
return Linkshare.objects.get_instance()
elif self.name == 'Commission Junction':
return CommissionJunction.objects.get_instance()
elif self.name == 'Share-A-Sale':
return ShareASale.objects.get_instance()
else:
raise Exception('Invalid aggregator name "%s". Excpected Linkshare, Commission Junction, or Share-A-Sale.' % self.name)
class Linkshare(models.Model):
def affiliate_properties(self, aggregator_affiliate_id):
return LinkshareExternalAffiliateProperties(aggregator_affiliate_id, self.username, self.password)
class Affiliate(models.Model):
foo = columns
def get_external_properties():
return self.aggregator.proxy.get_external_properties(self.aggregator_affiliate_id)
class MyView(self):
def view(self, request):
affiliate = get_object_or_404(Affiliate, pk=id)
properties = affiliate.get_external_properties()
return render_to_response('admin/affiliates/affiliate/affiliate_scrape_ajax.html', dict(scrape=properties))
在浏览器中命中/view会引发错误...
Hitting /view in the browser raises the error...
踢球者,在本地运行此代码,可以正常工作,而不会引发错误.
The kicker, running this code LOCALLY it works just fine w/o raising the error.
当我使用gunicorn&nginx,搞砸了.
When I run it using gunicorn & nginx, it messes up.
推荐答案
Gunicorn有一个错误:
Gunicorn has a bug:
django run_gunicorn
+重新加载
django run_gunicorn
+ reload
https://github.com/benoitc/gunicorn/issues/222
这篇关于super()参数1必须是类型,而不是无的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!