0

Im trying to get rid of 404 with Django local server. My page includes this:

<script type="text/javascript" src="{{ STATIC_URL }}js/myjscript.js"></script>

Actual file lies in C:/Users/PyCharmProjects/MyProject/MyApp/static/js/myjscript.js Django docs says:

Put your static files somewhere that staticfiles will find them.

By default, this means within static/ subdirectories of apps in your INSTALLED_APPS.

I believe my setup fit to defaults, but I still getting 404, why so? Kindly help!

UPDATE

Solved this with simply using template tag approach:

{% load static %}
<script type="text/javascript" src="{% static 'js/myjscript.js' %}"></script>

In the docs they saying about configuring STATICFILES_STORAGE, but I didnt even touch it, and get 200 for these files now.

This place of Django - static files - seems pretty dark and unclear for me. I cant understand purpose of such many sophisticated solutions for such simple task.

If somebody will point to good not-obscure manual for all this, I will highly appreciate!

Gill Bates
  • 14,330
  • 23
  • 70
  • 138

2 Answers2

1

Try

<script type="text/javascript" src="{{ STATIC_URL }}js/myjscript.js">

This page is where I got my information from.

In case that site is down, they give an example:

 <img src="{{ STATIC_URL }}images/hi.jpg" alt="Hi!" />
Nick ODell
  • 15,465
  • 3
  • 32
  • 66
0

Perhaps it goes without saying, make sure that STATIC_URL is set to something intelligent in your settings.py. I don't know what this gets set to by default in a Windows deployment.

john hight
  • 91
  • 6