简体   繁体   English

Django 1.5中的静态和媒体文件

[英]Static and Media files in django 1.5

I am making a site, I am the only one that will be uploading anything to the site. 我正在制作一个网站,我是唯一一个将任何内容上传到该网站的网站。 It seems like its more complicated to have two separate directories media and static would it be unreasonable to just funnel everything into static ? 拥有两个单独的目录mediastatic目录似乎更为复杂,仅将所有内容集中到static目录中是否合理?

I have not yet been able to figure out how to make Django serve my static files. 我还不能弄清楚如何使Django为我的静态文件服务。 I'm trying to have everything on the same server but have not had any success. 我试图将所有内容都放在同一台服务器上,但没有成功。 I have tried everything (at least I think I have) from http://djangoproject.com and I tried using this https://github.com/kennethreitz/dj-static earlier today but nothing seems to be working for me. 我已经尝试了http://djangoproject.com上的所有内容(至少我想已经),并且今天早些时候尝试使用此https://github.com/kennethreitz/dj-static ,但似乎没有任何用处。

My settings.py file: 我的settings.py文件:

MEDIA_ROOT = 'media'
MEDIA_URL = '/media/'
STATIC_ROOT = '/staticfiles/'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

My wsgi.py file 我的wsgi.py文件

import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

from django.core.wsgi import get_wsgi_application
from dj_static import Cling, MediaCling

application = Cling(MediaCling(get_wsgi_application()))

Conceptually it's better to separate static content (in /static/ ) from user-uploaded content (in /media/ ). 从概念上讲,最好将静态内容(在/static/ )与用户上传的内容(在/media/ )分开。 Even if you're the only one uploading to the site. 即使您是唯一上传到该网站的人。 For example, if you want to make a backup of your own uploads you know that backing up /media/ is sufficient. 例如,如果您要备份自己的上载,则知道备份/media/就足够了。 Your static content in /static/ should hopefully be part of a version control system so you don't need to back that up separately. 希望/static/静态内容应该是版本控制系统的一部分,因此您无需单独备份它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM