这一部分总共有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
如果有什么不对或者疑问的地方请指出,谢谢!