from django.urls import reverse#Django 2.0 remove django.core.urlresolver

Django 2.0 移除了django.core.urlresolver 模块 转换为django.urls 代替

python manage.py test --verbosity=2

Verbosity(冗长) determines the amount(数量) of notification(通知) and debug(调试) information that will be printed to the console(控制台); 0 is no output(输出), 1 is normal output, and 2 is verbose(冗长的) output


学习了第二章 superuser 管理员系统 Django有些强大  居然直接有后台管理系统 虽然是全英文的文档 但是简洁的语言还是令人心旷神宜的

------------------------------------分割线------2/19----------------------------------------------

test 文件中 必须先在数据库中创建新的实例


useful trick

Primary Key AutoField
Regex(正则) (?P<pk>\d+)
Example url(r'^questions/(?P<pk>\d+)/$', views.question, name='question')
Valid URL /questions/934/
Captures {'pk': '934'}
Slug Field
Regex (?P<slug>[-\w]+)
Example url(r'^posts/(?P<slug(鼻涕虫)>[-\w]+)/$', views.post, name='post')
Valid URL /posts/hello-world/
Captures {'slug': 'hello-world'}
Slug Field with Primary Key
Regex (?P<slug>[-\w]+)-(?P<pk>\d+)
Example url(r'^blog/(?P<slug>[-\w]+)-(?P<pk>\d+)/$', views.blog_post, name='blog_post')
Valid URL /blog/hello-world-159/
Captures {'slug': 'hello-world', 'pk': '159'}
Django User Username
Regex (?P<username>[\w.@+-]+)
Example url(r'^profile/(?P<username>[\w.@+-]+)/$', views.user_profile, name='user_profile')
Valid URL /profile/vitorfs/
Captures {'username': 'vitorfs'}
Year
Regex (?P<year>[0-9]{4})
Example url(r'^articles/(?P<year>[0-9]{4})/$', views.year_archive, name='year')
Valid URL /articles/2016/
Captures {'year': '2016'}
Year / Month
Regex (?P<year>[0-9]{4})/(?P<month>[0-9]{2})
Example url(r'^articles/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/$', views.month_archive, name='month')
Valid URL /articles/2016/01/
Captures {'year': '2016', 'month': '01'}

真的曲折 
{% load static %}

他必须放到最前面 

一个注释都不能有

------------------------------------分割线------2/20----------------------------------------------

base 创建模板 

{% block breadcrumb %}
        {% endblock %}

可以在里面插入 breadcrumb 在他的后代页面中

<title>{% block title %}Django Boards{% endblock %}</title>

当base页面中设定好 内容之后所有的子后代都会继承其中的内容


正则:$ 匹配为末尾位置


from django.shortcuts import render

render(request, template_name, context=None, content_type=None, status=None, using=None)

render方法

此方法的作用---结合一个给定的模板和一个给定的上下文字典,并返回一个渲染后的 HttpResponse 对象。

通俗的讲就是把context的内容, 加载进templates中定义的文件, 并通过浏览器渲染呈现.

resolve方法 :

from django.urls import resolve

作用:从URL得到url_name

reverse 是resolve的反向


assertContains(response, text, count=None, status_code=200, msg_prefix='', html=False)


断言response是否与status_code和text内容相应。将html设为True会将text作为html处理。


<input type="text" class="form-control" id="id_subject" name="subject">
this name

 The name will be used to retrieve(检索) the data on the server side.

在HTML 中使用board.topics.all:

Another important thing to note is that, inside Python code, we have to use parenthesis(插入语)board.topics.all(), because all() is a method. When writing code using the Django Template(模板) Language, in an HTML template file, we don’t use parenthesis, so it’s just board.topics.all.


board.topics.filter(subject__contains='Hello')过滤


test文件中的很多方法和爬虫有千丝万缕的关系