[Fixed]-Multiple Models on a Single View/Template in Django

1👍

The views:home, player and seasons are Function Based Views, this is the old Django Views style. On the other hand, ListView is a Class Based View, a newer way to write views in Django. You are mixing both kind of views and that’s a bad idea. No idea what your season view should do, but try something like:

def season(request, pk):
    season = get_object_or_404(Season, pk=pk) 
    return render(
        request, 
        'webapp/season.html',
        {'season': season, 'players': Player.objects.all()}
    )

0👍

In the url you need to call the class based view like, views.season.as_view()

Leave a comment