Skip to content

Serving django static files #249

Open
@R4z0R7

Description

@R4z0R7

Hello,

I noticed a problem with the static files in django applications. I have the following django app:

	"django": {
		"group": "djangotest",
		"home": "/home/djangotest/djenv",
		"module": "newtest.wsgi",
		"path": "/home/djangotest/newtest",
		"processes": 1,
		"type": "python 3.6",
		"user": "djangotest"
	}

This is a freshly-installed django 2.1 with no customisations. Python version is 3.6.8. The home page works fine but the stylesheets for the admin app return 404s.
I observed the same behaviour with images and static files in another django application, and I decided to test it with a clean installation of django.

The static URLs seem to be treated like standard urls and if they don't match anything in the urls.py file, they return a 404 instead of retrieving the file.

This is the error message from Django:

"Request Method: | GET
http://django.test/static/admin/css/base.css

Using the URLconf defined in newtest.urls, Django tried these URL patterns, in this order:
admin/
The current path, static/admin/css/base.css, didn't match any of these."

In Nginx Unit's access log, I see this:
"Not Found: /static/admin/css/base.css"

Static files are accessible when serving django with the built-in server for debugging and development. This only happens when the application is served by Unit.

I tried setting different environment variables for the application in Unit's configuration, such as STATIC_ROOT, STATIC_URL, STATIC_DIRS, DJANGO_SETTINGS_MODULE, etc., but none of these helped. Images and static files in the STATIC_ROOT directory would still not show.

Any ideas what might be wrong with the setup ?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions