当我运行本地服务器(./manage.py runserver 0.0.0.0:8000)时,如何查看STATIC_ROOT文件夹中的文件?我按照预期设置了django管道和集合作品,将缩小的文件放到STATIC_ROOT指定的目录中。但是,运行服务器并访问缩小的文件(在我的例子中是它的http://localhost:8000/static/filterpages/js/vendor.js)时,我会发现404页面没有找到。
我的目录树
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我的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'发布于 2016-04-03 14:26:46
你可以试试我的方法。在url.py (根url,放置在与settings.py文件相同的目录下)。
from django.conf.urls.static import static
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)并重新启动服务器,然后再次尝试访问js文件
https://stackoverflow.com/questions/36377397
复制相似问题