日62ジャンゴ管理/メディアの設定

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. データ入力用の管理ログインページ

メディアの設定

統一されたWebサイトを使用している静的ファイルは、静的なデフォルトフォルダを配置しています

ユーザーは、静的な限り、保存用に別のフォルダを確立する必要があり、ユーザーによってアップロードされたファイルの種類に関係なく、静的なファイルをアップロードするために、固定ファイルの下に配置する必要があります

メディアの設定

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

おすすめ

転載: www.cnblogs.com/2222bai/p/12018743.html