gpt4 book ai didi

syntax-error - 无效的语法错误-Python 3.5.2 Django 1.10

转载 作者:行者123 更新时间:2023-12-03 08:11:18 24 4
gpt4 key购买 nike

此处是Python/Django新手。我收到以下代码的语法错误,有人可以在这里帮助我吗? IDLE3在第16行的“宝藏”(“愚人节”)之前突出显示了它。

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')
]

最佳答案

您忘记在数组的元素后面加上逗号。像这样:

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')
]

关于syntax-error - 无效的语法错误-Python 3.5.2 Django 1.10,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38795421/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com