Josh Ellen
Josh Ellen

Reputation: 15

Referencing static files in Django

code example
tooltip file
searching for the correct path

FILES:

settings.py STATICFILES_DIRS = [ BASE_DIR / "static" , ]

base.html {% load static %}

How do I reference my static files in the following line of html code?...

<li class="ftco-animate"><a href="#" data-toggle="tooltip" data-placement="top" title="Facebook"><span class="ion-logo-facebook"></span></a></li>

i.e. {% static 'website/...' %}

Upvotes: 1

Views: 77

Answers (1)

Sakib Hasan
Sakib Hasan

Reputation: 487

As described in the docs, assuming your filepath is BASE_DIR/static/sub_dir/example.pdf you can reference it like this:

<li class="ftco-animate">
    <a href="{% static 'sub_dir/example.pdf' %}" data-toggle="tooltip" data-placement="top" title="Facebook">
        <span class="ion-logo-facebook"></span>
    </a>
</li>

It is good practice to place your static files in a sub-directory named same as your app name. That way, it will be much easier to reference the files from different apps later on. That is why the example in the docs says {% static 'my_app/example.jpg' %}.

Also please make sure you go through the documentations and follow all the steps mentioned there.

Upvotes: 1

Related Questions