• Django 中使用ImgFiled 和FileFiled


    1、使用ImgFiled

    class ImageField(upload_to=Noneheight_field=Nonewidth_field=Nonemax_length=100**options)[source]  返回资源

    必须在setting.py 中设置MEDIA

    setting.py

    MEDIA_URL = '/meta/'
    MEDIA_ROOT = os.path.join(BASE_DIR,'meta')

    models.py

    cover_map = models.ImageField(verbose_name='缩列图',upload_to='article/%Y/%m/%d',default='1.png')

    upload_to   上传的位置   最后会上传到  /meta/article/年/月/日/**.jpg  

    如果要显示需要在urls.py设置

    from django.contrib import admin
    from django.urls import path
    from django.urls import include
    from django.conf import settings
    from django.conf.urls.static import static
    
    urlpatterns = [
        path('admin/', admin.site.urls),
        path('polls/', include('polls.urls')),
        path('download/', include('download.urls')),
        path('article/', include('article.urls')),
    ]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
    僵尸将臣
  • 相关阅读:
    Android学习——day13
    寒假周总结三
    构建之法读书笔记03
    Android学习——day12
    每日日报2020 11/18
    每日日报2020 11/17
    每日日报2020 11/16
    每日日报2020 11/15
    每日日报2020 11/13
    每日日报2020 11/12
  • 原文地址:https://www.cnblogs.com/sunshenggang/p/9572664.html
Copyright © 2020-2023  润新知