static files not found on development server

658 views
Skip to first unread message

Axel Rau

unread,
Jul 6, 2017, 5:04:56 AM7/6/17
to Django users
Hi,

I can’t find the answer to this simple question:

Why do I get
[06/Jul/2017 09:54:20] "GET /static/css/bootstrap.min.css HTTP/1.1" 404 1676
on development server, while on production server, it works.

In production, I have
<link href=„{{ STATIC_URL }}css/bootstrap.min.css" rel="stylesheet" media="screen">

On development, I have tried this and this:
<link href=„{% static 'css/bootstrap.min.css' %}" rel="stylesheet" media="screen">
Both do not work.

Config on (pathes have been checked and are ok):

INSTALLED_APPS = (
. . .
‚django.contrib.staticfiles',
. . .
)


MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'APP_DIRS': False,
'DIRS': [os.path.join(BASE_DIR, 'templates'),],
'OPTIONS': {
'context_processors': [
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.request',
'django.template.context_processors.static',
'django.contrib.messages.context_processors.messages',
],
# start - please add only if APP_DIRS is False
'loaders': [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
],
# end - please add only if APP_DIRS is False
'debug': True
}
}
]
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, „static")
##print(‚STATIC_ROOT = {}'.format(os.path.abspath(STATIC_ROOT)))

In production config, I have both staticfiles app and static template.context_processors disabled.

Thanks, Axel
---
PGP-Key:29E99DD6 ☀ computing @ chaos claudius

Melvyn Sopacua

unread,
Jul 6, 2017, 5:45:21 AM7/6/17
to django...@googlegroups.com

[Assuming the weird opening quote comma replacement is formatting, not actual code]

 

On Thursday 06 July 2017 11:03:19 Axel Rau wrote:

 

> Why do I get

> [06/Jul/2017 09:54:20] "GET /static/css/bootstrap.min.css HTTP/1.1"

> 404 1676 on development server, while on production server, it works.

>

> In production, I have

> <link href=„{{ STATIC_URL }}css/bootstrap.min.css" rel="stylesheet"

> media="screen">

 

On production, you're running a webserver that serves the `/static` url and have run `python manage.py collectstatic`.

 

On development, you're running a webserver that doesn't know the `/static` url or failed to run `python manage.py collectstatic`.

 

--

Melvyn Sopacua

Axel Rau

unread,
Jul 6, 2017, 6:14:11 AM7/6/17
to Django users

Am 06.07.2017 um 11:44 schrieb Melvyn Sopacua <m.r.s...@gmail.com>:

On development, you're running a webserver that doesn't know the `/static` url or failed to run `python manage.py collectstatic`.
On development, I run the django-admin runserver, which AFAIK should take care of the static path.
I have checked out the static stuff on dev (static/), which was commited on prod server.

Andreas Schosser

unread,
Jul 6, 2017, 12:22:10 PM7/6/17
to django...@googlegroups.com
Hi Alex

> On development, I run the django-admin runserver, which AFAIK should take care of the static path.

Did you restart the development server. I think the static files are
collected at startup and newly added files are not recognized on the fly.

Andreas

--
Kurs 10 IT-Consulting www.kurs-10.de
Andreas Schosser a...@kurs-10.de

Baldestraße. 14 Telefon +49 89 41615842-0
80469 München Telefax +49 89 41615842-3

0x6EDECCF1 - 2AA0 939B 5585 819B FCE8 E43B 0B8E 0DF2 6EDE CCF1

Antonis Christofides

unread,
Jul 6, 2017, 1:56:57 PM7/6/17
to django...@googlegroups.com
No, the development server recognizes new static files on the fly. However, it
can sometimes fail; for example, if you have removed the directory and recreate
it. So restarting it is a good idea when you are trying to debug it.

Antonis Christofides
http://djangodeployment.com
Reply all
Reply to author
Forward
0 new messages