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(正則) | |
Example | |
Valid URL | |
Captures | |
Slug Field | |
---|---|
Regex | |
Example | |
Valid URL | |
Captures | |
Slug Field with Primary Key | |
---|---|
Regex | |
Example | |
Valid URL | |
Captures | |
Django User Username | |
---|---|
Regex | |
Example | |
Valid URL | |
Captures | |
Year | |
---|---|
Regex | |
Example | |
Valid URL | |
Captures | |
Year / Month | |
---|---|
Regex | |
Example | |
Valid URL | |
Captures | |
真的曲折
{% 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檔案中的很多方法和爬蟲有千絲萬縷的關系