所以我想保存一個Django模型,並出於某種原因,我只得到500內部服務器錯誤。事實是,Django模型不保存時調用保存()
如果我評論的social_auth.save()它的工作原理,我可以操縱 對象,但不能將其保存
爲什麼會出現這種情況?我正在使用django tastypie,我正在嘗試保存一個django-social-auth實例。
def obj_create(self, bundle, request=None, **kwargs):
try:
#this is not supposed to upgrade password
bundle = super(UserResource, self).obj_create(bundle)
bundle.obj.save()
if bundle.data.get('extra_data') != None:
print bundle.data.get('extra_data')
fb_id = bundle.data.get('extra_data')['id']
#social_auth=UserSocialAuth(user_id = bundle.obj, provider=bundle.data.get('provider'),uid=fb_id,extra_data=bundle.data.get('extra_data'))
social_auth=UserSocialAuth()
social_auth.user_id = bundle.obj
social_auth.provider=bundle.data.get('provider')
social_auth.uid=fb_id
social_auth.extra_data=bundle.data.get('extra_data')
print "social: ",social_auth.extra_data
social_auth.save()
except IntegrityError:
raise BadRequest('Username already exists')
return bundle
回溯:
Traceback (most recent call last):
File "temp_3.py", line 23, in <module>
post()
File "temp_3.py", line 18, in post
f = urllib2.urlopen(req)
File "/usr/lib/python2.7/urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib/python2.7/urllib2.py", line 406, in open
response = meth(req, response)
File "/usr/lib/python2.7/urllib2.py", line 519, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python2.7/urllib2.py", line 444, in error
return self._call_chain(*args)
File "/usr/lib/python2.7/urllib2.py", line 378, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 527, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 500: INTERNAL SERVER ERROR
這是什麼e堆棧跟蹤說? – karthikr
什麼都沒有,但我只是追加 – psychok7
以上的回溯,如果bundle.obj類型爲'User',那麼'social_auth.user_id = bundle.obj'是錯誤的,應該是'social_auth.user = bundle.obj' –