glasslion / django-qiniu-storage

Django storage for 七牛云存储

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

请问下存放在static目录里面的资源和存放在media目录里面的资源,能否使用不同域名提供服务

shineforever opened this issue · comments

看到demo_site里面有以下字段,感觉应该是支持再同一个BUCKET下,static和media支持不通的域名吧?

#七牛给开发者分配的 AccessKey
QINIU_ACCESS_KEY = "xxxxxxxxxxxxxxxx"
#七牛给开发者分配的 Secret
QINIU_SECRET_KEY = "xxxxxxxxxxxxx"
#用来存放文件的七牛空间(bucket)的名字
QINIU_BUCKET_NAME = "test"
#对象存储对应的域名
QINIU_BUCKET_DOMAIN = "img.xxx.info"
#是否通过 HTTPS 来访问七牛云存储上的资源(若为'是', 可填True, true 或 1;若为'否', 可填False, false 或 0) 默认为否
QINIU_SECURE_URL = False

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/var/www/example.com/media/"
MEDIA_ROOT = '/media'

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://example.com/media/", "http://media.example.com/"
MEDIA_URL = 'http://img.xxxx.info/media/'

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/var/www/example.com/static/"
STATIC_ROOT = '/static'

# URL prefix for static files.
# Example: "http://example.com/static/", "http://static.example.com/"
STATIC_URL = 'http://static.xxx.info/static/'

# Additional locations of static files
STATICFILES_DIRS = (
    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

# Make this unique, and don't share it with anybody.
SECRET_KEY = '9=mp)3*)4=bf_)-rf^4&34shdwqsmtn%bh#!lw^s$1i=#c4s&@'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
#     'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    # Uncomment the next line for simple clickjacking protection:
    # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'demo_site.urls'

# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'demo_site.wsgi.application'

TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'qiniustorage',
    'foo',
    'bar',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
)



#存放用户上传的资源,如图片;
DEFAULT_FILE_STORAGE = 'qiniustorage.backends.QiniuMediaStorage'
#存放js,css等静态资源
STATICFILES_STORAGE = 'qiniustorage.backends.QiniuStaticStorage'

但是static这个域名好像没有生效,网站引用的还是img.xxx.info这个域名?!

Django 静态资源的 url 是根据 STATIC_URL 算出来的。 你贴的配置应该是正确的。

你说的是用 {% static %} template tag 得到的, 还是自己拼的?