How can I view files inside STATIC_ROOT folder when I run local server (./manage.py runserver 0.0.0.0:8000)? I set up django-pipeline and collectstatic works as expected by putting minified file into directory designated by STATIC_ROOT. However, running the server and accessing minified file (in my case its http://localhost:8000/static/filterpages/js/vendor.js ) gives me 404 page not found.
My directory tree
django_project/
├── filter
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── filterpages
│ ├── admin.py
│ ├── apps.py
│ ├── __init__.py
│ ├── migrations
│ ├── models.py
│ ├── static
│ │ └── filterpages
│ │ ├── js
│ │ └── vendor
│ │ ├── bootstrap.min.js
│ │ └── jquery-2.2.2.min.js
│ ├── templates
│ │ └── filterpages
│ │ ├── index.html
│ ├── templatetags
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── manage.py
└── staticfiles
├── admin
└── filterpages
├── js
│ ├── vendor.6238a90960e0.js
│ └── vendor.js
└── vendor
├── bootstrap.min.c5b5b2fa19bd.js
├── bootstrap.min.js
├── jquery-2.2.2.min.1d35678c5edb.js
└── jquery-2.2.2.min.js
My settings.py
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_STORAGE = 'pipeline.storage.PipelineStorage'
STATICFILES_DIRS = []
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'pipeline.finders.CachedFileFinder',
'pipeline.finders.PipelineFinder',
'pipeline.finders.FileSystemFinder',
)
PIPELINE = {
'PIPELINE_ENABLED': True,
'JAVASCRIPT': {
'vendor': {
'source_filenames': (
'filterpages/vendor/jquery.min.js',
'filterpages/vendor/bootstrap.min.js',
),
'output_filename': 'filterpages/js/vendor.js',
}
}
}
PIPELINE['JS_COMPRESSOR'] = 'pipeline.compressors.yuglify.YuglifyCompressor'
You can try my way. In url.py (root url, place at same directory with settings.py file).
from django.conf.urls.static import static
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
And restart server and try again to access js file
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.