oTree Forum >

Presenting a different image to different players

#1 by Rotem

I'm now to Otree experiment designed. This must be very basic but I can't get it to work.

I'm trying to present an image to the participants depending on their id_in_group. the images are stored in app1121 directory in the _static root folder and names infoset1.1, infoset1.2... The images should be presented on the instructions.html page.
I have the following code in my __init.py__

class instructions(Page):
    def vars_for_template(player: Player):
        return dict(
        image_path ='app1121/infoset1.{}.png'.format(player.id_in_group)
and this in my  instructions.html page
<p><img src="{{  static image_path  }}"/></p>

but I get this error message:

Application error (500)
UndefinedVariable: Cannot resolve the variable 'image_path' (line 25, in "static") 

Help, please!

#2 by Rotem

I've worked it out, in case someone else has this challenge 

    def vars_for_template(player: Player):
        id_in_group = player.id_in_group
        base_number = 1
        pic_address = 'app1121/infoset{}.{}.png'.format(base_number, id_in_group)
        return dict(

Write a reply

Set forum username