這一部分總共有3個小項目:
- 外星人入侵
- 數據可視化
- Web應用程序
第一個的遊戲照着做沒什麼問題,主要的問題在後面兩個項目,大多是python庫的版本問題。
第三個項目已經上傳到github:https://github.com/11ze/learning_log
並部署到heroku:http://wangze-log.herokuapp.com/
下面是遇到的問題及解決方案:
一、數據可視化:
- 沒有pygal.i18n
解決: pip install pygal_maps_world
- 繪製世界地圖時: module 'pygal' has no attribute 'Worldmap'
解決: import pygal.maps.world
wm = pygal.maps.world.World()
- 注意 很多API都要求你註冊獲得API密鑰後才能執行API調用。編寫本書時,GitHub沒有這樣的要求,但獲得API密鑰後,配額將高得多。
- pygal繪圖: 'NoneType' object has no attribute 'decode'
解決: 'label': str(repo_dict['description'])
二、第18章:
- django外鍵: __init__() missing 1 required positional argument: 'on_delete'
解決: hbook = models.ForeignKey('BookInfo', on_delete=models.CASCADE)
參考: https://www.cnblogs.com/endurance9/p/8083747.html
- django,urls,path: https://blog.csdn.net/chenguang79/article/details/80733657
- 第18章參考: https://blog.csdn.net/weixin_40576260/article/details/79480508
- django2.0: No module named 'django.core.urlresolvers'
解決: django.urls
參考: https://blog.csdn.net/weixin_35757704/article/details/78977753
三、第19章:
- django2.0: cannot import name 'login'
解決: 一樣的效果
from django.contrib.auth.views import login
-> from django.contrib.auth.views import LoginView
path('login/', LoginView.as_view(template_name='users/login.html'),
name='login'),
參考: http://tieba.baidu.com/p/5490650117
- django學習——Django中authenticate和login模塊: https://blog.csdn.net/geerniya/article/details/78959897
- 重建數據庫: python manage.py flush, 但既有數據全部清空
四、第20章:
- heroku部署問題, You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path.
解決: 在setting.py中
if os.getcwd() == '/app': # 獲取當前工作目錄
->if os.environ['HOME'] == '/app': # 獲取HOME目錄
參考: https://blog.csdn.net/tymatlab/article/details/78391483