django上传图片问题

最近这个在admin上传图片的东西搞的我非常郁闷,求教了很多人,查了很多资料。知道问题出在setting.py中的路径,但是怎么着改都有问题,今晚实在没辙就完全推倒重做,又仔细的分析了一遍media_root,media_url,static_root,static_url,admin_media_prefix。参考帮助文档,终于搞定,mark一下。

> MEDIA_ROOT

the directory where you upload media

> MEDIA_URL

the url where your site media – css, js, icons etc live

> ADMIN_MEDIA_PREFIX

the alias to where the admin media lives – django/contrib/admin/media

设置好setting.py文件后,在urls.py文件中添加一个urlpattern,如下代码:

url(r'^media/(?P<path>.*)$',
        'django.views.static.serve',
        {'document_root': settings.MEDIA_ROOT}
   ),


setting

Tags:

One Response to “django上传图片问题”

  1. 我来逛逛,顺便帮博主顶一下

    ReplyReply

Leave a Reply