ss7
ss7

Reputation: 3012

Django Template Variables in static path

I have a template where I need to access a directory based on the user's fields.

The code looks like this:

{% with user.client.company as company %}
{% static 'uploads/{{ company }}' as files %}
{% endwith %}

I also tried:

{% static 'uploads/{% user.client.company %}' as files %}

How can I achieve this? I want the folder name to be equal to user.client.company but right now I get an error like:

Invalid block tag: 'static', expected 'endwith' for the first one and

Invalid block tag: 'static' for the second

Obviously I am doing it wrong. Any help would be much appreciated.

It was pointed out I should use media rather than static. But even so, I am unsure how to dynamically set the path based on the user's parameters.

Upvotes: 1

Views: 1108

Answers (1)

flakes
flakes

Reputation: 23674

remember to load you statics!!

{% load staticfiles %}

Upvotes: 1

Related Questions