0

I have a Model called Game and in that model i have the attribute game_image where i store a name of an image i want to search in a folder, for example: example.jpg, and i wanted to use that atributte inside a form

this is the Game Model code

class Game(models.Model):
     game_image = models.CharField(max_length=200, default='DEFAULT VALUE')

i wanted to use the attribute here, instead of example.jpg i wanted to get game_image and search for the image in the folder according to the attribute

this is the code i have:

<img src="{% static 'app/images/example.jpg' %}" />

i wanted something like this:

<img src="{% static 'app/images/game.image' %}" />

I understand that this question is probably really dumb but i would aprecciate any help, if you need more code just say, thanks

GamerGirl
  • 25
  • 1
  • 5
  • It's not a dumb question - it's tripped other people up before! Looks like http://stackoverflow.com/questions/16655851/django-1-5-how-to-use-variables-inside-static-tag might solve your problem? That question assumes that you have access to a Game model as a variable in your template already, but hopefully the Django docs can show you how to do that. – bouteillebleu May 06 '17 at 15:10
  • 1
    @bouteillebleu thank you so much, it did solve the problem :D – GamerGirl May 06 '17 at 15:33
  • Possible duplicate of [django 1.5 - How to use variables inside static tag](http://stackoverflow.com/questions/16655851/django-1-5-how-to-use-variables-inside-static-tag) – e4c5 May 07 '17 at 04:02

1 Answers1

0

It works now, if anyone wants to know how it worked i only changed the code to the one bellow, thanks for the help.

<img src="{% with 'app/images/'|add:game.game_image|add:'.jpg' as image_static %}
                {% static image_static %}
          {% endwith %}" />
GamerGirl
  • 25
  • 1
  • 5