0

django 2.0.3 and Python 3.6.x FireFox, Chrome, Safari

I'm not sure that this is a django issue as this is something I've never seen happen. I am hoping someone has seen this before or knows what I am doing wrong.

My browser will not find my static files with runserver. What is strange is that the urls within the templates are correct and if I paste the urls into the browser, the files are found.

If I run

./manage.py findstatic --verbosity 2 css/style.css

The files are found. Yet the browser, Firefox, Chrome, Safari (all latest versions) both show a 404 in the WebConsoles of the pages where I access the static resources.

<link rel="stylesheet" href="{% static 'trans/css/style.css?1510690221335' %}">

Does not work. If I change to the actual URL

<link rel="stylesheet" href="http://localhost:8080/trans/css/style.css?1510690221335">

Things work fine.

My relevant (As best I can tell) configuration is

STATIC_ROOT = str(ROOT_DIR('staticfiles'))

STATIC_URL = '/static/'

STATICFILES_DIRS = [
    str(APPS_DIR.path('static')),
]

/#staticfiles-finders

STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]

I also added

static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

to my urls.py

All permissions on my static folder and sub folders are correct. Has anyone seen this before and know of a resolution? Thank you.

Sebastien D
  • 4,369
  • 4
  • 18
  • 46
chuck
  • 19
  • 1
  • 5

2 Answers2

0

I had same issue, when i place my static files in a folder that doesn't correspond to my app name follow the step below

  1. Make sure that django.contrib.staticfiles is included in your INSTALLED_APPS.
  2. In your settings file, define STATIC_URL, for example:

    STATIC_URL = '/static/'

  3. In your templates, use the static template tag to build the URL for the given relative path using the configured STATICFILES_STORAGE.

    {% load static %}

    src="{% static "my_app/example.jpg" %}"

  4. Store your static files in a folder called static in your app. For example my_app/static/my_app/example.jpg

see full documentation here

Ochui Princewill
  • 148
  • 1
  • 15
0

static tag escapes question mark (it did not in previous versions).

So move ? outside of tag call:

<link rel="stylesheet" href="{% static 'trans/css/style.css' %}?1510690221335">

should work.

Looks like a bug.

Ivan Starostin
  • 8,798
  • 5
  • 21
  • 39