Django 使用笔记

  • 了解 django REST framework(可以了解整个 API 设计所涉及的技术

django 最佳实践类

  • django 项目里面要不要出现 controller,为什么?

django’s cache framework

design philosophy

  1. less code
  2. consistency
  3. extensibility

django model field

null vs blank

Field.null: If True, Django will store empty values as NULL in the database. Default is False.

Field.blank: If True, the field is allowed to be blank. Default is False. Note that this is different than null. null is purely database-related, whereas blank is validation-related. If a field has blank=True, form validation will allow entry of an empty value. If a field has blank=False, the field will be required.

auto_now vs auto_now_add

auto_now: Automatically set the field to now every time the object is saved. auto_now_add: when created

django 测试的坑

  1. 如果你 mock 了 django 的某个函数,这个函数返回的值之后要更新到数据库,这时: 一定要记得把这个 mock 掉的函数的返回值写好,不然会遇到奇怪的错误。比如碰到这种错误,大概有种*了狗的感觉

FieldError: Aggregate functions are not allowed in this query

Updated:

Comments