私は Django/python を使用していますが、いくつかのエラーが発生しました。オンラインで関連する回答が見つからないようです。
私はviews.pyから以下をテストしていました:
def teamRoster(request, pk): #shows list of players
tempteams = Teams.objects.get(id=pk)
tempteams = tempteams.players.all()
team = get_object_or_404(Teams, id=pk)
context = {
'teamList': tempteams,
'team': team,
}
return render(request, "roster/teamRoster.html", context)
シェルで得られるもの:
from roster.models import Teams, Player
tempteams=Teams.objects.get(id=pk)
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'pk' is not defined
次の行を試してみると:
tempteams = tempteams.players.all()
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'tempteams' is not defined
私のデータには、自動的に割り当てられる代わりに、json ファイルを作成するときに入れた pk 属性があります。pk を定義する必要がある場所がわかりません。私はdjango/pythonでかなり新しいですが、別の定義(同じプロジェクト)で同様のことを行いましたが、正常に動作します。どんなガイダンスでも大歓迎です。それが役に立ったら、私のモデルとコードの他の部分はhttps://github.com/historymaiden/Athletic-Team-Appにあります- アプリは名簿と呼ばれます。