<Effective Django>读书笔记
- In Django parlance, a project is the final product, and it assembles one or more applications together.
- Manage.py is a pointer back to Django-admin.py with an environment variable set, pointing to your project as the one to read settings from and operate on when needed
- Settings.py is where you’ll configure your project. It has a few sensible defaults, but no database chosen when you start.
- Urls.py contains the URL to view mappings.
- Wsgi.py is a WSGI wrapper for your application.
- Beginning in Django 1.4, apps are placed alongside project packages.
- Models.py will contain the Django ORM models for your app.
- Views.py will contain the View code
- Tests.py will contain the unit and integration tests you write
- Django models map to a database table, and provide a place to encapsulate business logic. All models subclass the base Model
- The INSTALLED_APPS setting lists the applications that the project uses. These are listed as strings that map to Python packages. Django will import each and looks for a models there.
- By default Django will name your tables using a combination of the application name and model name.
- Django adds an id field as the primary key for your model, unless you specify a primary key.
- The syncdb manage command creates the tables in your database from models.
- The model Manager allows you to operate on the collection of instanes: querying, creating, etc
- Write unit tests for methods you add to the model
- The test manage command runs the unit tests.
- Django Views take an HTTP Request and return an HTTP Response to the user.
- Any Python callable can be a view. The only hard and fast requirement is that it takes the request object (customarily named request) as its first argument.
- Generic Views have always provided some basic functionality: render a template, redirect, create or edit a model.
- The URL configuration tells Django how to match a request’s path to your Python code. Django looks for the URL configuration, defined as urlpatterns, in the urls.py file in your project.
- By default Django will look for templates in applications, as well as in directories you specify in settings.TEMPLATE_DIRS.
- Most generic views that do form processing have the concept of the “success URL”: where to redirect the user when the form is successfully submitted.
- The collection of values available to a template when it’s rendered is referred to as the Context. The Context is a combination of information supplied by the view and information from context processors
- Django has two tools that are helpful for writing unit tests for views: the Test Client and the RequestFactory
- The TestClient takes a URL to retrieve, and resolves it against your project’s URL configuration. It then creates a test request, and passes that request through your view, returning the Response.
- Django supports adding static files at both the application and project level. Where you add them sort of depends on how tied to your specific assembly of apps they are.
- App specific static files are stored in the static subdirectory within the app. Django will also look in any directories listed in the STATIFFILES_DIRS setting.
- Django distinguishes between static site files, and user upload media.
- The staticfiles app is included to help manage static files and serve them during development.
- Static files can be included with apps, or with the project.
- Templates can extend one another, using block tags.
- A Django Form is responsible for taking some user input, validating it, and turning it into Python objects.
- Initial is a dictionary of values that will be used as the default values for an unbound form
- Forms have two different phases of validation: field and form. All the fields are validated and converted to Python objects (if possible) before form validation begins.
- Form validation takes place in a form’s clean() method
- Forms take user input, validate it, and convert it to Python objects.
- Django provides 3 types of fields for relating objects to each other: ForeignKey for creating one to many relationships, ManyToManyField for relating many to many, and OneToOneField for creating a one to one relationship.
- A FormSet is an object that manages multiple copies of the same Form(or ModelForm) in a single page.
<Effective Django>读书笔记的更多相关文章
- csapp读书笔记-并发编程
这是基础,理解不能有偏差 如果线程/进程的逻辑控制流在时间上重叠,那么就是并发的.我们可以将并发看成是一种os内核用来运行多个应用程序的实例,但是并发不仅在内核,在应用程序中的角色也很重要. 在应用级 ...
- CSAPP 读书笔记 - 2.31练习题
根据等式(2-14) 假如w = 4 数值范围在-8 ~ 7之间 2^w = 16 x = 5, y = 4的情况下面 x + y = 9 >=2 ^(w-1) 属于第一种情况 sum = x ...
- CSAPP读书笔记--第八章 异常控制流
第八章 异常控制流 2017-11-14 概述 控制转移序列叫做控制流.目前为止,我们学过两种改变控制流的方式: 1)跳转和分支: 2)调用和返回. 但是上面的方法只能控制程序本身,发生以下系统状态的 ...
- CSAPP 并发编程读书笔记
CSAPP 并发编程笔记 并发和并行 并发:Concurrency,只要时间上重叠就算并发,可以是单处理器交替处理 并行:Parallel,属于并发的一种特殊情况(真子集),多核/多 CPU 同时处理 ...
- 读书笔记汇总 - SQL必知必会(第4版)
本系列记录并分享学习SQL的过程,主要内容为SQL的基础概念及练习过程. 书目信息 中文名:<SQL必知必会(第4版)> 英文名:<Sams Teach Yourself SQL i ...
- 读书笔记--SQL必知必会18--视图
读书笔记--SQL必知必会18--视图 18.1 视图 视图是虚拟的表,只包含使用时动态检索数据的查询. 也就是说作为视图,它不包含任何列和数据,包含的是一个查询. 18.1.1 为什么使用视图 重用 ...
- 《C#本质论》读书笔记(18)多线程处理
.NET Framework 4.0 看(本质论第3版) .NET Framework 4.5 看(本质论第4版) .NET 4.0为多线程引入了两组新API:TPL(Task Parallel Li ...
- C#温故知新:《C#图解教程》读书笔记系列
一.此书到底何方神圣? 本书是广受赞誉C#图解教程的最新版本.作者在本书中创造了一种全新的可视化叙述方式,以图文并茂的形式.朴实简洁的文字,并辅之以大量表格和代码示例,全面.直观地阐述了C#语言的各种 ...
- C#刨根究底:《你必须知道的.NET》读书笔记系列
一.此书到底何方神圣? <你必须知道的.NET>来自于微软MVP—王涛(网名:AnyTao,博客园大牛之一,其博客地址为:http://anytao.cnblogs.com/)的最新技术心 ...
- Web高级征程:《大型网站技术架构》读书笔记系列
一.此书到底何方神圣? <大型网站技术架构:核心原理与案例分析>通过梳理大型网站技术发展历程,剖析大型网站技术架构模式,深入讲述大型互联网架构设计的核心原理,并通过一组典型网站技术架构设计 ...
随机推荐
- 一步一步掌握java的线程机制(二)----Thread的生命周期
之前讲到Thread的创建,那是Thread生命周期的第一步,其后就是通过start()方法来启动Thread,它会执行一些内部的管理工作然后调用Thread的run()方法,此时该Thread就是a ...
- Fiddler高级用法-抓取手机app数据包
在上一篇中介绍了Fiddler的基本使用方法.通过上一篇的操作我们可以直接抓取浏览器的数据包.但在APP测试中,我们需要抓取手机APP上的数据包,应该怎么操作呢? Andriod配置方法 1)确保手机 ...
- logstash日志分析的配置和使用(转)
logstash是一个数据分析软件,主要目的是分析log日志.整一套软件可以当作一个MVC模型,logstash是controller层,Elasticsearch是一个model层,kibana是v ...
- ROC 曲线简要解释
阳性 (P, positive)阴性 (N, Negative)真阳性 (TP, true positive):正确的肯定.又称:命中 (hit)真阴性 (TN, true negative):正确的 ...
- centos 7部署graphite(nginx+uwsgi)
http://www.debugrun.com/a/o5qyP9W.htmlhttp://blog.csdn.net/tsingfu1986/article/details/44239503 http ...
- Jenkins管理静态资源
这里我们的前端是使用webpack来管理静态资源的,把静态资源上传到svn上面来管理 这里我们把项目和静态资源剥离开来,然后静态资源接入CDN 我们的svn的结构是这样的 我们需要把这些目录都进行打包 ...
- java空指针异常
我们都知道java是没有指针的,这里说的"java指针"指的就是java的引用,我们不在这里讨论叫指针究竟合不合适,而只是针对这个异常本身进行分析.空指针就是空引用,java空指针 ...
- 在Android Studio 和 Eclipse 的 git 插件操作 "代码提交"以及"代码冲突"
面向对象:曾经使用过SVN的同学. (因为Git 它 可以说是双重的SVN (本地一个服务器,远程一个服务器)),提交代码要有两次步骤,先提交到本地服务器,再把本地服务器在提交到远程服务器. 所以连S ...
- spring(四) 手动整合web项目(SSH)
清楚了spring的IOC 和 AOP,最后一篇就来整合SSH框架把,记录下来,以后应该会用的到. --WH 一.web项目中如何使用spring? 当tomcat启动时,就应该加载spring的配置 ...
- 【Unity】11.3 基本碰撞体(箱体、球形、胶囊、网格)
分类:Unity.C#.VS2015 创建日期:2016-05-02 一.简介 碰撞组件(Collider) 是另一种必须随刚体 (Rigidbody) 添加的组件,以便允许它和其他组件发生碰撞.或者 ...