我正在使用Django 1.5.1 / python 2.7.3 还有virtualenv
我无法将我的媒体委托给'django.contrib.staticfiles.views',其中存储的文件由app django-ckeditor上传到管理界面
静态文件服务良好,但媒体(用户图像)效果不佳。例如它返回
http://127.0.0.1:8000/media/home/raido/dev/project/project/media/Raido/2013/08/28/4bebf51c0a5b.jpg
如果我调整链接到http://127.0.0.1:8000/media/Raido/2013/08/28/4bebf51c0a5b.jpg
,它会返回404,并调试我的网址
my urls.py
from django.conf.urls import patterns, url, include
from lessons.views import LessonListView, LessonDetailView
from ckeditor import urls
from django.conf import settings
from django.conf.urls.static import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns = patterns('',
url(r'^$', LessonListView.as_view(), name='list'),
url(r'^(?P<pk>\d+)/$', LessonDetailView.as_view()),
url(r'^ckeditor/', include('ckeditor.urls')),
)
if settings.DEBUG:
urlpatterns += patterns('django.contrib.staticfiles.views',
url(r'^static/(?P<path>.*)$', 'serve'),
url(r'^media/(?P<path>.*)$', 'serve'),
)
settings.py
import os
_PATH = os.path.dirname(os.path.abspath(__file__))
MEDIA_ROOT = "/home/raido/dev/project/project/media/"
MEDIA_URL = '/media/'
STATIC_ROOT = "/home/raido/dev/project/project/static"
STATIC_URL = '/static/'
STATICFILES_DIRS = (
...
os.path.join(_PATH, 'static'),
)
TEMPLATE_DIRS = (
os.path.join(_PATH, 'templates'),
)
TEMPLATE_CONTEXT_PROCESSORS = (
....
'django.core.context_processors.static',
)
CKEDITOR_UPLOAD_PATH = "/home/user/dev/project/project/media/"
CKEDITOR_RESTRICT_BY_USER = True
我的树-L 4
.
├── deploy
│ └── nginx
│ ├── project.conf
│ └── projectDeploy.conf
├── favicon.ico
├── lessons
│ ├── admin.py
│ ├── admin.pyc
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── migrations
│ │ ├── 0001_initial.py
│ │ ├── 0001_initial.pyc
│ │ ├── __init__.py
│ │ └── __init__.pyc
│ ├── models.py
│ ├── models.pyc
│ ├── templates
│ │ └── lessons
│ │ ├── lesson_detail.html
│ │ └── lesson_list.html
│ ├── tests.py
│ ├── urls.py
│ ├── urls.pyc
│ ├── views.py
│ └── views.pyc
├── logs
│ ├── nginx_access.log
│ └── nginx_error.log
├── manage.py
├── media
│ └── Raido
│ └── 2013
│ └── 08
├── news
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── models.py
│ ├── models.pyc
│ ├── tests.py
│ └── views.py
├── project
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── settings_deploy.py
│ ├── settings.py
│ ├── settings.pyc
│ ├── static
│ │ ├── css
│ │ │ ├── foundation.css
│ │ │ ├── foundation.min.css
│ │ │ └── normalize.css
│ │ ├── humans.txt
│ │ ├── img
│ │ ├── index.html
│ │ ├── js
│ │ │ ├── foundation
│ │ │ ├── foundation.min.js
│ │ │ ├── jquery.js
│ │ │ └── vendor
│ │ └── robots.txt
│ ├── templates
│ │ ├── 404.html
│ │ ├── 500.html
│ │ └── base.html
│ ├── urls.py
│ ├── urls.pyc
│ ├── wsgi.py
│ └── wsgi.pyc
├── pids
├── README.md
└── stati
答案 0 :(得分:0)
urlpatterns = patterns('',
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/',
# include('django.contrib.admindocs.urls')),
....
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)urlpatterns += staticfiles_urlpatterns()
这就是我如何服务我的媒体