zoukankan      html  css  js  c++  java
  • Django 设置media static

    Django 设置media static

    本文python版本3.6.1,Django版本1.11.1

    1、settings.py配置

    增加django.template.context_processors.media

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    TEMPLATES = [
        {
            'BACKEND': 'django.template.backends.django.DjangoTemplates',
            'DIRS': [os.path.join(BASE_DIR, 'templates')]
            ,
            'APP_DIRS': True,
            'OPTIONS': {
                'context_processors': [
                    'django.template.context_processors.debug',
                    'django.template.context_processors.request',
                    'django.contrib.auth.context_processors.auth',
                    'django.contrib.messages.context_processors.messages',
                    'django.template.context_processors.media',
                ],
            },
        },
    ]

    增加MEDIA_URL、MEDIA_ROOT

    1
    2
    3
    MEDIA_URL = '/media/'
     
    MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

    2、urls.py

    1
    2
    3
    4
    5
    from east_web.settings import MEDIA_ROOT
    from django.views.static import serve
     
    # 配置上传文件的访问处理函数
        url(r'^media/(?P<path>.*)$',  serve, {"document_root": MEDIA_ROOT}),

    3、models.py使用

    1
    image = models.ImageField(max_length=100, upload_to="image/%Y/%m", default=u"image/default.png", verbose_name=u'头像')

    4、xadmin后台页面展示

    5、media目录

     
  • 相关阅读:
    ABAP-Spotlight on ABAP for SAP HANA – Again
    ABAP-ABAP Development
    ABAP-Performance Guidelines for ABAP Development on the SAP HANA Database
    ABAP-Getting Started with ABAP Core Data Services (CDS)
    ABAP-Technology and Runtime Environment
    ABAP-Test and Analysis Tools
    ABAP-Connectivity Wiki
    python爬虫
    python爬虫
    python爬虫
  • 原文地址:https://www.cnblogs.com/huchong/p/7873288.html
Copyright © 2011-2022 走看看