A
A
Anton2018-09-22 05:23:57
Django
Anton, 2018-09-22 05:23:57

How to write a static file in Django?

Something I can’t figure out how to link a static file to a project in Django. In different places, this process is described in different ways, which makes you even more confused :(
I did this: in settings.py I wrote STATIC_URL = '/static/' and in INSTALLED_APPS 'django.contrib.staticfiles', (more precisely, he was registered there). By the way, one more question follows from this: is it necessary to
register STATICFILES_DIRS and why and what to write there? I
created a static folder in it js and put the file itself in it:
5ba5a3a446a77217201053.png
... For example, at the moment it is written like this: {% load staticfiles %}

<img src="{% static "mysite/js/Chart.js" %}" alt="My js"/>

At the same time, js is available through the browser's address bar: 127.0.0.1:8000/static/js/Chart.js
Something like this.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2018-09-24
@8toni8

As a result, this is how it turned out to be inserted:
<script src="/static/js/Chart.js"></script>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question