Opened 4 years ago

Closed 4 years ago

#31497 closed Bug (worksforme)

get_static_prefix() as variable in a template doesn't work. — at Version 1

Reported by: Thiago Krempser Owned by: nobody
Component: contrib.staticfiles Version: 3.0
Severity: Normal Keywords: get_static_prefix, static
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Mariusz Felisiak)

I'm using Django 3.0 and I tried to use this suggestion from the Django 3.0 documentation (https://docs.djangoproject.com/en/3.0/ref/templates/builtins/#get-static-prefix):

{% load static %}
{% tkrempser as STATIC_PREFIX %}

<img src="{{ STATIC_PREFIX }}images/hi.jpg" alt="Hi!">
<img src="{{ STATIC_PREFIX }}images/hi2.jpg" alt="Hello!">

But STATIC_PREFIX variable is empty and nothing is printed on template.

Using the other suggestion:

{% load static %}
<img src="{% get_static_prefix %}images/hi.jpg" alt="Hi!">

It works as expected.

Change History (1)

comment:1 by Mariusz Felisiak, 4 years ago

Component: Documentationcontrib.staticfiles
Description: modified (diff)
Resolution: worksforme
Status: newclosed
Summary: get_static_prefix as variable in a template not workingget_static_prefix() as variable in a template doesn't work.

Thanks for this ticket, however it works for me, it can be some issue in your templates. Please use one of support channels.

Note: See TracTickets for help on using tickets.
Back to Top