I'm trying to compile static with django-pipeline, but can't manage to serve static in dev mode. Since I'm not a Django developer, I may be wrong how Django serves static files itself. Here's my project structure:
- project (project itself)
- project (settings, global urls config, etc.)
- app (main and the only app)
- static (app-based static files, namespaced via app name folder)
- static (shared static, that's not linked to specific app)
- css
- app.styl
- css
- public
- media
- static (not used in dev env; only for production: should be served with nginx, auto-generated via collectstatic)
As I'm using shared static, I've specified STATICFILES_DIRS
directive to allow Django dev server and collectstatic
command to find shared static:
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
Here's my settings.py
:
# for production, should be served via nginx
STATIC_ROOT= os.path.join(BASE_DIR, 'public/static/')
# prefix for static app
STATIC_URL = '/static/'
# also django-pipeline config
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'pipeline.finders.PipelineFinder',
)
STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'
PIPELINE = {
'PIPELINE_ENABLED': True,
'COMPILERS': (
'pipeline.compilers.stylus.StylusCompiler',
),
'STYLESHEETS': {
'app': {
'source_filenames': (
'css/app.styl',
),
'output_filename': 'css/app.css',
},
},
}
In my template I've specified CSS-group:
{% load pipeline %}
{% stylesheet 'app' %}
</head>
As a result, such HTML is generated:
<link href="/static/css/app.css" rel="stylesheet" type="text/css" />
</head>
But /static/css/app.css
returns 404.
If I run collectstatic
, public/static/css/app.css
is built. But as I understand Django logic, it's used only for apache/nginx-based production serving and not in dev one. In dev mode static is served via internal Django server with some middleware django-pipeline hooks.
What I'm doing wrong? Any help is appreciated, thanks.
UPD: I've added + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
to global urlpatterns, however can't understand it's why it's recommended — STATIC_ROOT is used only for production with external proxy-server and not with Django itself. Or not?