2016-08-05 31 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。 –