oTree Forum >

Admin Report

#1 by tim3178

Hello, 
I'm currently discovering otree. First of all, thanks a lot for all the help I found on this forum!

While coding my app, I encountered some troubles with the Admin report.
I've read the doc here: https://otree.readthedocs.io/es/latest/admin.html#admin-reports

In the subsession class, I have created this function :
class Subsession(BaseSubsession):
    def vars_for_admin_report(self):
        players = self.get_players()
        return dict(
            total_players = len(players),
        )

And in my admin_report.html, for now, i've just written this to test my code :
<p>Total players : {{ total_players }}</p>

However I end up with this issue:
otree.templating.errors.UndefinedVariable: Cannot resolve the variable 'total_players' (line 3, in "total_players")

Am I missing something here? Should I put my function vars_for_admin_report somewhere else?

Thanks for your help

#2 by Daniel_Frey

Your method needs to be placed without an indent, not part of the class Subsession.

The way you coded it, it won't get called.

#3 by tim3178

Hello Daniel_Frey, thanks a lot, it worked

Write a reply

Set forum username