0

added a new static file to my project by copy/paste into the static directory for my project. But I get 'File not found' when checking debug mode in the browser.

This is my folder structure:

- static
  - projectname
      -OldScript.js
      -NewAwesomeScript.js

And this is my base.html

<script src="{% static 'projectname/OldScript.js' %}" type="text/javascript"></script>
<script src="{% static 'projectname/NewAwesomeScript.js' %}" type="text/javascript"></script>

This is the staticfiles_dir in settings.py:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))    

STATICFILES_DIRS = [
        os.path.join(BASE_DIR, "static"),
    ]

The oldscript.js have been in the project for a long time. Just wanted to add a new static file I need to load in base.html. So after copying the file to my folder I copy the include script code and changed the name to NewAwesomeScript.js.

It's not working and when checking debug in the browser, it says 'File not found 404'.

OldScript.j is loading, NewAwesomeScript.js is not loading.

Copy from Header for the old file that works:

Request URL:http://localhost:8000/static/projectname/OldScript.js
Request Method:GET
Status Code:200 OK (from disk cache)
Remote Address:127.0.0.1:8000
Referrer Policy:no-referrer-when-downgrade

And the Header for the new file:

Request URL:http://localhost:8000/static/projectname/NewAwesomeScript.js
Request Method:GET
Status Code:404 Not Found
Remote Address:127.0.0.1:8000
Referrer Policy:no-referrer-when-downgrade

Tried forcing refresh (ctrl + shift + F5)

I have restarted the server instance. It's in development. So not a production. Therefore I do not need to run 'collectstatic'. But desperate as I am, I also did this.

I have also checked read/write privileges.

Trying to find anything in the documentation about adding new static files. Without luck to finding my mistake.

What have I forgotten to do?

sumpen
  • 503
  • 6
  • 19
  • Are you sure there's no typos? What exactly is the url that gives you the 404? Are you sure there's no duplicate `OldScript.js` served from a different directory? Are you using the builtin django `runserver`? – Håken Lid Nov 21 '17 at 13:44
  • Did you run `collectstatic`? – The_Cthulhu_Kid Nov 21 '17 at 13:47
  • are you sure {% load static %} is above the call to the script? – yoyoyoyo123 Nov 21 '17 at 13:48
  • @HåkenLid Hej, Yes I double checked for typos. Copy filenames from file to code. I added Header from the browser. As you see one get 404. I Tried forcing refresh of page. – sumpen Nov 21 '17 at 13:54
  • perhaps your static settings is wrong.. let me see your settings.py – binpy Nov 21 '17 at 13:56
  • see if this helps - https://stackoverflow.com/questions/27911070/django-wont-refresh-staticfiles – yoyoyoyo123 Nov 21 '17 at 13:56
  • @The_Cthulhu_Kid Not applicable since this is in development. But as I wrote. Desperate as I am, I did this also. Totally in vain. – sumpen Nov 21 '17 at 13:58
  • @bvmcode Yes I have ***load static***, otherwise I wouldn't be able to include the file that works. And the question you referred to is valid for production. And I tried all the answers there. Thanks anyway – sumpen Nov 21 '17 at 14:00
  • @SancaKembang Since the oldscript is loading from same location, the settings are not the problem. But I'll edit the question with settings for ***STATICFILES_DIR***. – sumpen Nov 21 '17 at 14:03
  • What is the output of [this management command](https://docs.djangoproject.com/en/1.11/ref/contrib/staticfiles/#findstatic)? `python manage.py findstatic projectname/NewAwesomeScript.js projectname/OldScript.js --verbosity 2` – Håken Lid Nov 21 '17 at 14:15

0 Answers0