【发布时间】:2015-08-05 01:08:45
【问题描述】:
我有这个 Django 网络应用程序,它允许用户上传各种视频文件。这些目录都在媒体下,并且创建任何子目录以唯一标识文件。我已经在提供静态文件,但我想做的只是提供整个“媒体”目录。有什么简单的方法可以提供服务吗?
"""
Django settings for elearn project.
For more information on this file, see
https://docs.djangoproject.com/en/1.7/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.7/ref/settings/
"""
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
TEMPLATE_DIRS = (
BASE_DIR + '/templates/',
)
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
#DEBUG = False
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = ['*']
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'lessons',
'registration'
)
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',
)
ROOT_URLCONF = 'app.urls'
WSGI_APPLICATION = 'app.wsgi.application'
# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
'/elearn/static',
)
STATIC_URL = '/static/'
我故意遗漏了敏感凭据。
这也是我目前提供静态文件的方式
) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
谢谢
【问题讨论】:
标签: python django django-staticfiles