django-tables2: how to pass other object instance to the template besides the one we use for the table

StackOverflow https://stackoverflow.com/questions/14654691

  •  06-03-2022
  •  | 
  •  

Question

I created a table using django-tables2 and everything is working fince except that I want to add other instances or variable to the url template.

Here is my view:

def SpecificPLayer(request, playerslug):

    player = Player_Bios.objects.get(player_id=playerslug)
    table= StatTable(BatStat.objects.filter(player_id=playerslug).values('season','team_id'))
    RequestConfig(request, paginate=False).configure(table)

    return render(request, 'singleplayer.html', {'table': table})

What about if I want to pass the following to the template:

today = date.today() 

My common sense told me to do this:

 return render(request, 'singleplayer.html','today':taday {'table': table}) #does not work

on my singleplayer.html, I have the following:

  {{ today }}
Was it helpful?

Solution

the answer is:

 return render(request, 'singleplayer.html', {'table': table, 'today':taday})

OTHER TIPS

You need to have all of the variable that you want to use in the view inside the dictionary.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top