2016-08-05 30 views
1

Python/Django newcomer here。我得到一個語法錯誤,下面的代碼,任何人都可以幫我在這裏? IDLE3之前突出顯示了16號線「寶物」(「愚人金牌」)。無效的語法錯誤 - Python 3.5.2 Django 1.10

from django.shortcuts import render 

# Create your views here. 
def index(request): 
    return render(request, 'index.html', {'treasures':treasures}) 

class Treasure: 
    def __init__(self, name, value, material, location): 
     self.name = name 
     self.value = value 
     self.material = material 
     self.location = location 

treasures = [ 
    Treasure('Gold Nugget', 500.00, 'gold', "Curley's Creek, NM") 
    Treasure("Fool's Gold", 0, 'pyrite', "Fool's Falls, CO") 
    Treasure('Coffee Can', 20.00, 'tin', 'Acme, CA') 
] 
+0

寶之間缺少昏迷對象 –

回答

0

你忘了在數組元素之後加逗號。就像這樣:

treasures = [ 
    Treasure('Gold Nugget', 500.00, 'gold', "Curley's Creek, NM"), 
    Treasure("Fool's Gold", 0, 'pyrite', "Fool's Falls, CO"), 
    Treasure('Coffee Can', 20.00, 'tin', 'Acme, CA') 
] 
+0

事實上,我需要把元素後,逗號數組...那是個漫長的一天!感謝Jean-FrançoisFabre和Runner。 –