settings里设置好media_root
import os
HERE = os.path.dirname(os.path.dirname(__file__))
MEDIA_ROOT = os.path.join(HERE, "media").replace('\', '/')
MEDIA_URL = "/site_media/"
models里面使用字段
content = UEditorField(u"内容", imagePath="uploadimg/",blank=True, null=True)
urls里面加入
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
例如:
urlpatterns = patterns('',
url(r'^xadmin/', include(xadmin.site.urls), name='xadmin'),
url(r'^ueditor/', include('DjangoUeditor.urls' )),
)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
这样就可以避免后端配置不正确,不能上传图片。