第一次印刷
第3章 - 3.4.2 - 52 頁,感謝 @止沸 的指正
拼寫錯誤,少了個s,錯誤內容:
MIDDLEWARE = [ 'student.middleware.TimeItMiddleware', # 省略其他 ]
修訂爲:
MIDDLEWARE = [ 'student.middlewares.TimeItMiddleware', # 省略其他 ]
第4章 - 4.2.1 小節 - 70頁,感謝 @Yangzhedi 的指正
- 拼寫錯誤,錯誤內容:
$ source bin/activite
- 修訂爲:
$ source bin/activate
- 拼寫錯誤,錯誤內容:
第5章 - 5.4.5 - 106 頁, 感謝 @jasonqiao36 的指正
縮進問題,錯誤內容:
from django.db.models import F post = Post.objects.get(id=1) post.pv = F('pv') + 1 pos.save()
修訂爲:
from django.db.models import F post = Post.objects.get(id=1) post.pv = F('pv') + 1 post.save()
第7章 - 7.2.2 小節 - 147頁,感謝 @092113219,@faple 的指正
缺少返回值,錯誤內容:
@classmethod def latest_posts(cls): queryset = cls.objects.filter(status=cls.STATUS_NORMAL)| $ source bin/activate |
修訂爲:
@classmethod def latest_posts(cls): queryset = cls.objects.filter(status=cls.STATUS_NORMAL) return queryset
第9章 - 9.5.2 - 205 頁,感謝 @moneys 的指正
拼寫錯誤,錯誤內容:
if not cache.get(uv_key): increase_uv = True cache.set(pv_key, 1, 24*60*60)
修訂爲:
if not cache.get(uv_key): increase_uv = True cache.set(uv_key, 1, 24*60*60)
第二印
第 3 章 - 3.4.3 - 56 頁 - 漏寫括號, 感謝 @weixianshan 的指正
錯誤內容:
讀者可以嘗試把test.py文件中的 student.sex_show 改爲student.get_sex_display試試。
修改爲:
讀者可以嘗試把test.py文件中的 student.sex_show 改爲student.get_sex_display()試試。
第 6 章 - 6.2.2 - 122 頁 typo,感謝 圖靈社區 @zerosail @PaperSheep 的指正
- 錯誤內容:
filter_horizontal = ('tags', ) filter_vertical = ('tags', )
- 應改爲:
filter_horizontal = ('tag', ) filter_vertical = ('tag', )
- 錯誤內容:
第 6 章 - 6.3.1 - 130 頁 - 重複,感謝 圖靈社區 @zerosail 的指正
錯誤內容: save_on_top = True
該行代碼與第129頁的倒數第三行代碼重複了
第8章 - 8.2.2 - 179 頁,感謝「Django企業開發實戰」 @秋 的指正
拼寫錯誤,錯誤內容:
<span class="card-link">分類:<a href="{% url 'category-list' cate.id %}">{{ post.category.name }}</a></span>
修訂爲:
<span class="card-link">分類:<a href="{% url 'category-list' post.category.id %}">{{ post.category.name }}</a></span>
第11章 - 11.1.1 - 237 頁,感謝 @eat 的指正
djangorestframewrok 包錯寫爲 django-rest-framework,錯誤內容:
pip install django-rest-framework==3.8.2
修訂爲:
pip install djangorestframework==3.8.2
第 14 章 - 14.3.4 - 308 頁 supervisor 已經支持 Python 3
需要修改內容:
對這些配置有了大概的瞭解後,需要先來安裝: ``pip install supervisor``這裏需要注意的是,我們對於目前的使用方式有兩種,主要是在Python 2和Python 3項目中的差別,對於Python 2的項目,我們會在虛擬環境中安裝supervisor。而在Python 3中會在系統上安裝,虛擬環境使用系統(全局)的supervisor來管理進程。這麼用的原因在於supervisor針對Python 3的版本還沒有最終release。 不過對於個人項目可以嘗試直接從github安裝最新的包: ``pip install git+https://github.com/Supervisor/supervisor``,使用基於兼容了Python3的版本。我們這裏也是從github安裝目前最新的supervisor(4.0.0dev0)。 或者使用作者fork出來的分支做的release: pip install https://github.com/the5fire/supervisor/archive/4.0.0dev0.zip
修改爲:
對這些配置有了大概的瞭解後,需要先來安裝: ``pip install supervisor==4.0.2``。
第14章 - 14.3.6 - 312 頁
djangorestframewrok 包錯寫爲 django-rest-framework,錯誤內容:
django-rest-framework==0.1.0
修訂爲:
djangorestframework==3.8.2
第三印
第1章 - 1.4.1 - 10 頁,數據庫實體對象圖中 datetime 字段類型錯誤,感謝 Github 網友:@panxingj 的反饋
錯誤內容爲:
圖中 SideBar 實體中的 created_time 字段類型設置爲 str
修訂爲
SideBar 中的 created_time 字段類型應該爲 datetime
第1章 - 1.4.2 - 11 頁,腦圖部分在線鏈接問題,感謝公衆號讀者:sky 的反饋
短網址被新浪限頻了,錯誤內容: 上圖使用百度腦圖工具製作,在線版:http://t.cn/R14lkXe 密碼: GTDL
修正爲:
上圖使用百度腦圖工具製作,在線版:http://naotu.baidu.com/file/3f7f8238a936155341cac37aaac40a66?token=96dd1b636b4bc558 密碼: GTDL
第3章 - 3.4.2 - 52 頁,感謝 圖靈社區@hanshanjie 提醒
英文語法錯誤,錯誤內容:
print('request to response cose: {:.2f}s'.format(costed))
修訂爲:
print('request to response cost: {:.2f}s'.format(costed))
第5章 - 5.4.2 - 103頁,感謝 Github 網友 @jpch89 的指正
第二行代碼少了縮進:
try: post = Post.objects.get(id=1) # 其餘代碼省略
修訂爲:
try: post = Post.objects.get(id=1) # 其餘代碼省略
第6章 - 6.1.1 - 114 頁, 感謝 Github 網友 @jpch89 的指正
內容優化,原內容爲:
list_display_links: 用來配置哪些字段可以作爲鏈接,點擊它們,可以進入編輯頁面。
優化爲
list_display_links: 用來配置哪些字段可以作爲鏈接,點擊它們,可以進入編輯頁面。如果設置爲 None,則表示不配置任何可點擊的字段。
第6章 - 6.2.1 - 119 頁,感謝 圖靈社區@limyel 提醒
代碼優化,待優化內容:
def queryset(self, request, queryset): category_id = self.value() if category_id: return queryset.filter(category_id=self.value()) return queryset
修訂爲:
def queryset(self, request, queryset): category_id = self.value() if category_id: return queryset.filter(category_id=category_id)) return queryset
第6章 - 6.2.4 - 123 頁, 感謝 Github 網友 @jpch89 的指正
字段名寫錯,原內容:
我們通過 Form 來定製 status 這個字段的展示:
修訂爲:
我們通過 Form 來定製 desc 這個字段的展示:
第6章 - 6.3 - 127 頁, 感謝 Github 網友 @jpch89 的指正
方法名寫錯
之前我們在 PostAdmin 中重寫了 save 方法
修訂爲
之前我們在 PostAdmin 中重寫了 save_model 方法
第6章 - 6.3.1 - 129 頁
代碼優化,待優化內容:
def queryset(self, request, queryset): category_id = self.value() if category_id: return queryset.filter(category_id=self.value()) return queryset
修訂爲:
def queryset(self, request, queryset): category_id = self.value() if category_id: return queryset.filter(category_id=category_id)) return queryset
第8章 - 8.2.2 - 178 頁, 感謝 Github 網友 @jpch89 的指正
代碼錯誤,action 修改爲 method 原內容爲:
<form class="form-inline my-2 my-lg-0" action='GET'>
修訂爲:
<form class="form-inline my-2 my-lg-0" method='GET'>
第9章 - 9.1.1 - 185頁, 感謝 Github 網友 @jpch89 的指正
SQL 字段寫錯,原內容爲:
SELECT * FROM post WHERE title ILIKE '%<keyword>%' or title ILIKE '%<keyword>%'
修訂爲:
SELECT * FROM post WHERE title ILIKE '%<keyword>%' or desc ILIKE '%<keyword>%'
未歸類:
https://github.com/the5fire/django-practice-book/issues/34
https://github.com/the5fire/django-practice-book/issues/35
https://github.com/the5fire/django-practice-book/issues/40
提交勘誤渠道:
- Github: https://github.com/the5fire/django-practice-book/issues
- 圖靈社區:http://www.ituring.com.cn/book/2663
《Django企業開發實戰》購買地址: