zoukankan      html  css  js  c++  java
  • Day 62 Django后台管理/MEDIA配置

    Django后台管理

    1. 先去应用下的admin.py中注册你想要管理的模型类

      from django.contrib import admin
      from app01 import models
      # Register your models here.
      
      
      admin.site.register(models.Userinfo)
      admin.site.register(models.Blog)
      admin.site.register(models.Category)
      admin.site.register(models.Tag)
      admin.site.register(models.Article)
      admin.site.register(models.UpAndDown)
      admin.site.register(models.Article2Tag)
      
    2. 注册一个超级用户

      python manage.py.createsuperuser
      
    3. 登录admin页面进行数据录入

    MEDIA配置

    网站所用到的静态文件统一默认都放在static文件夹下

    用户上传的静态文件也应该单独建立一个文件夹进行存储,无论用户上传什么类型的文件,只要是静态的,都应该放在某一固定的文件下

    MEDIA配置

    在settings.py中配置

    MEDIA_ROOT = os.path.join(BASE_DIR,'media')
    

    在urls.py中添加url

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

    TruncMonth

    # django 官网给你提供了一个方法
    	from django.db.models.functions import TruncMonth
    
    # -官方提供
    	from django.db.models.functions import TruncMonth
    	Sales.objects
    	.annotate(month=TruncMonth('timestamp'))  # Truncate to month and add to select list
    	.values('month')  # Group By month
    	.annotate(c=Count('id'))  # Select the count of the grouping
    	.values('month', 'c')  # (might be redundant, haven't tested) select month and count
    
  • 相关阅读:
    easyui的页面等待提示层,即mask
    easyui datebox 只选择年月
    java poi Excel导入 整数浮点数转换问题解决
    js去除日期字符串时分秒
    获得元素上的所有属性
    人月神话阅读笔记(二)
    人月神话读后感(一)
    独立冲刺阶段(四)
    独立冲刺阶段(三)
    独立冲刺阶段(二)
  • 原文地址:https://www.cnblogs.com/2222bai/p/12018743.html
Copyright © 2011-2022 走看看