1、在models.py
文件中定义如下字段
icon=models.ImageField(u'图标',upload_to='img/%Y/%m/%d')
2、在setting.py
文件中设置如下:
MEDIA_URL='/uploads/'MEDIA_ROOT=os.path.join(BASE_DIR, 'uploads')
3、在urls.py
文件中设置:
from django.conf.urls.static
import staticfrom django.conf import settings
urlpatterns = [
........此处省略n个字
]+static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)```
最后的效果会是:`http://www.xxxxxx.com/uploads/img/2016/10/28/xxxxx.jpg`
网友评论