AttributeError : '목록'개체에 '개체'속성이 없습니다.

깊은

나는 던지고있는 다음을 실행하려고합니다.

AttributeError : '목록'개체에 '개체'속성이 없습니다.

script.py

#Get Dota2 Item Rarities
dotaItemRarityUrl = 'http://api.steampowered.com/IEconDOTA2_570/GetRarities/v1?'
dotaItemRarityPayload = {'key': settings.SOCIAL_AUTH_STEAM_API_KEY,
                    'language': 'en',
                    }
dotaItemRarityInfo = requests.get(dotaItemRarityUrl, params=dotaItemRarityPayload)
dotaItemRarity = dotaItemRarityInfo.json()
dotaItemRarity = dotaItemRarity['result']['rarities']
print(dotaItemRarity)
#print(dotaItemQualities)

#Populate Database With Item Rarities that do NOT exist already
for rarity in dotaItemRarity:
    print rarity
    irarityId = rarity['id']
    irarityProperName = rarity['localized_name']
    irarityInternalName = rarity['name']
    irarityColor = rarity['color']

    q = dotaItemRarity.objects.filter(rarityId=irarityId)
    print q

    if len(q) == 0:
        newRarity = dotaItemRarity(rarityId=irarityId,
                                   rarityProperName=irarityProperName,
                                   rarityInternalName=irarityInternalName,
                                   rarityColor=irarityColor)
        newRarity.save()

models.py

class dotaItemRarity(models.Model):
    rarityId = models.IntegerField(max_length=3,primary_key=True)
    rarityProperName = models.CharField(max_length=60)
    rarityInternalName = models.CharField(max_length=50)
    rarityColor = models.CharField(max_length=30)

    def __unicode__(self):
        return self.rarityInternalName

나는 마이그레이션을 처리하기 위해 남쪽을 사용하고 있으며 테이블을 제거하고 다시 작성하는 등 여러 옵션을 시도하여이를 수정했습니다. 이것이 효과가 있다고 말할 수있는 한 누구든지 올바른 방향으로 나를 가리킬 수 있습니까?

Martijn Pieters

dotaItemRarity목록이며 objects속성 이 없습니다 .

q = dotaItemRarity.objects.filter(rarityId=irarityId)

JSON 결과의 목록에 바인딩했기 때문입니다.

dotaItemRarity = dotaItemRarityInfo.json()
dotaItemRarity = dotaItemRarity['result']['rarities']

예상대로 Django 모델 아닙니다 .

당신이 가지고있는 경우 dotaItemRarity에 수입 장고 모델을 script.py, 그 이름은 목록과 교체로 더 이상 그 모델에 바인딩하지 않습니다.

모델을 마스킹하지 않는 다른 이름을 사용하도록 목록 이름을 바꿉니다.

있습니다 파이썬 스타일 가이드는 당신이 그런 실수를 방지하기 위해, (장고 모델을 포함) 클래스 낙타 표기법 이름을 사용하는 것이 좋습니다.

PEP 8에 따라 코드를 약간 리팩터링하고 더 명확한 이름 지정 방법을 사용합니다.

models.py:

class DotaItemRarity(models.Model):
    rarity_id = models.IntegerField(max_length=3, primary_key=True)
    rarity_proper_name = models.CharField(max_length=60)
    rarity_internal_name = models.CharField(max_length=50)
    rarity_color = models.CharField(max_length=30)

    def __unicode__(self):
        return self.rarity_internal_name

script.py:

#Get Dota2 Item Rarities
url = 'http://api.steampowered.com/IEconDOTA2_570/GetRarities/v1'
payload = {'key': settings.SOCIAL_AUTH_STEAM_API_KEY, 'language': 'en'}
response = requests.get(url, params=payload)
rarities = response.json()['result']['rarities']

for rarity in rarities:
    rarity_id = rarity['id']

    try:
        DotaItemRarity.get(rarity_id=rarity_id)
    except DotaItemRarity.DoesNotExist:
        new_rarity = DotaItemRarity(
            rarityId=rarity_id,
            rarity_proper_name=rarity['localized_name'],
            rarity_internal_name=rarity['name'],
            rarity_color=rarity['color'])
        new_rarity.save()

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

AttributeError : '목록'개체에 '시간'속성이 없습니다.

분류에서Dev

AttributeError : '목록'개체에 'barh'속성이 없습니다.

분류에서Dev

AttributeError : '목록'개체에 '복사'속성이 없습니다.

분류에서Dev

Python 연결된 목록 AttributeError : 'NoneType'개체에 'next'속성이 없습니다.

분류에서Dev

Python AttributeError : 큐를 사용한 후 '목록'개체에 속성이 없습니다.

분류에서Dev

AttributeError : '목록'개체에 Selenium Python 속성 '대체'가 없습니다.

분류에서Dev

목록 개체 렌더링 문제 : AttributeError : 'list'개체에 '...'속성이 없습니다.

분류에서Dev

목록 내 목록에 추가하면 AttributeError : 'int'개체에 'append'속성이 없습니다.

분류에서Dev

Seaborn 제목 오류-AttributeError : 'FacetGrid'개체에 'set_title 속성이 없습니다.

분류에서Dev

AttributeError : 'ExceptionResponse'개체에 '등록'속성이 없습니다 (TCP / IP를 통한 ModbusRTU)?

분류에서Dev

이 AttributeError : 'SubRequest'개체에 'getfuncargvalue'속성이 없습니다.

분류에서Dev

목록 요소 'list'개체에 'replace'속성이 없습니다.

분류에서Dev

'목록'개체에 'foreach'속성이 없습니다.

분류에서Dev

'NoneType'개체의 목록에 '그룹'속성이 없습니다.

분류에서Dev

'목록'개체에 속성이 없습니다.

분류에서Dev

AttributeError : '모듈'개체에 wxPython에 'PyScrolledWindow'속성이 없습니다.

분류에서Dev

AttributeError : 'str'개체에 tkinter에 'set'속성이 없습니다.

분류에서Dev

/ api / test 유형 개체 '제품'의 AttributeError에 '개체'속성이 없습니다.

분류에서Dev

AttributeError : 'NoneType'개체에 'iterrows'속성이 없습니다.

분류에서Dev

AttributeError : 'NoneType'개체에 'iterrows'속성이 없습니다.

분류에서Dev

Keras : AttributeError : 'int'개체에 'lower'속성이 없습니다.

분류에서Dev

AttributeError : 'Series'개체에 'upper'속성이 없습니다.

분류에서Dev

AttributeError : 'int'개체에 '_get_xf_index'속성이 없습니다.

분류에서Dev

/ jobseeker / addskills 'list'개체의 AttributeError에 'jobseeker'속성이 없습니다.

분류에서Dev

AttributeError : 'function'개체에 'predict'속성이 없습니다. 케 라스

분류에서Dev

AttributeError : '모듈'개체에 'DEVNULL'속성이 없습니다.

분류에서Dev

AttributeError : 'SendGridAPIClient'개체에 'send'속성이 없습니다.

분류에서Dev

AttributeError : 'scoped_session'개체에 '세션'속성이 없습니다.

분류에서Dev

"AttributeError : 'NoneType'개체에 '삽입'속성이 없습니다."

Related 관련 기사

  1. 1

    AttributeError : '목록'개체에 '시간'속성이 없습니다.

  2. 2

    AttributeError : '목록'개체에 'barh'속성이 없습니다.

  3. 3

    AttributeError : '목록'개체에 '복사'속성이 없습니다.

  4. 4

    Python 연결된 목록 AttributeError : 'NoneType'개체에 'next'속성이 없습니다.

  5. 5

    Python AttributeError : 큐를 사용한 후 '목록'개체에 속성이 없습니다.

  6. 6

    AttributeError : '목록'개체에 Selenium Python 속성 '대체'가 없습니다.

  7. 7

    목록 개체 렌더링 문제 : AttributeError : 'list'개체에 '...'속성이 없습니다.

  8. 8

    목록 내 목록에 추가하면 AttributeError : 'int'개체에 'append'속성이 없습니다.

  9. 9

    Seaborn 제목 오류-AttributeError : 'FacetGrid'개체에 'set_title 속성이 없습니다.

  10. 10

    AttributeError : 'ExceptionResponse'개체에 '등록'속성이 없습니다 (TCP / IP를 통한 ModbusRTU)?

  11. 11

    이 AttributeError : 'SubRequest'개체에 'getfuncargvalue'속성이 없습니다.

  12. 12

    목록 요소 'list'개체에 'replace'속성이 없습니다.

  13. 13

    '목록'개체에 'foreach'속성이 없습니다.

  14. 14

    'NoneType'개체의 목록에 '그룹'속성이 없습니다.

  15. 15

    '목록'개체에 속성이 없습니다.

  16. 16

    AttributeError : '모듈'개체에 wxPython에 'PyScrolledWindow'속성이 없습니다.

  17. 17

    AttributeError : 'str'개체에 tkinter에 'set'속성이 없습니다.

  18. 18

    / api / test 유형 개체 '제품'의 AttributeError에 '개체'속성이 없습니다.

  19. 19

    AttributeError : 'NoneType'개체에 'iterrows'속성이 없습니다.

  20. 20

    AttributeError : 'NoneType'개체에 'iterrows'속성이 없습니다.

  21. 21

    Keras : AttributeError : 'int'개체에 'lower'속성이 없습니다.

  22. 22

    AttributeError : 'Series'개체에 'upper'속성이 없습니다.

  23. 23

    AttributeError : 'int'개체에 '_get_xf_index'속성이 없습니다.

  24. 24

    / jobseeker / addskills 'list'개체의 AttributeError에 'jobseeker'속성이 없습니다.

  25. 25

    AttributeError : 'function'개체에 'predict'속성이 없습니다. 케 라스

  26. 26

    AttributeError : '모듈'개체에 'DEVNULL'속성이 없습니다.

  27. 27

    AttributeError : 'SendGridAPIClient'개체에 'send'속성이 없습니다.

  28. 28

    AttributeError : 'scoped_session'개체에 '세션'속성이 없습니다.

  29. 29

    "AttributeError : 'NoneType'개체에 '삽입'속성이 없습니다."

뜨겁다태그

보관