新的URL - yann学长的运维开发指南41

in #devops8 years ago

大纲

第6章的内容还是比较激动的,在这个章节里会完成一个可用的网站
加上域名就可以对外展示的那种

http://www.iamyann.com/images/0621/20180621204227.png
(html comment removed: more)

内容介绍

  • 新的URL
  • 新建清单测试
  • 添加模板
  • 建立新的模板
  • 修改模板和视图

新的URL

在之前的测试中,发现需要额外的一个URL,不能用首页来展示查询内容

所以本章就造一个URL出来

新建清单测试

再新建一个测试

vi lists/tests.py

http://www.iamyann.com/images/0621/20180621201550.png

添加模板

测试失败

python manage.py test lists

AssertionError: False is not true : Template 'list.html' was not a template
used to render the response. Actual template(s) used: home.html

缺少模板

vi lists/views.py

http://www.iamyann.com/images/0621/20180621201855.png

建立新的模板

再次测试

python manage.py test lists

django.template.exceptions.TemplateDoesNotExist: list.html

报没有模板

touch lists/templates/list.html
python manage.py test lists

AssertionError: False is not true : Couldn't find 'itemey 1' in response'

告警有了变化

修改模板和视图

复制home.html的内容,再做一些修改

cp lists/templates/home.html lists/templates/list.html

vi lists/templates/home.html
vi lists/views.py

http://www.iamyann.com/images/0621/20180621202957.png

http://www.iamyann.com/images/0621/20180621203035.png

再次进行测试

python manage.py test lists

AssertionError: '1: Buy milk' not found in ['1: Buy peacock feathers', '2: Buy
milk']

新配置的URL起作用了,和首页区分开来

预告

战线拖的太长,我也快归纳不出全局了,下节要更新下结构,突出大纲

时间过的飞快,下节再见

http://hero.iamyann.com/blog_webchat.jpg