我们的博客虽然还有很多不完善的地方,但是没关系,越早把它部署到互联网上,才能越早发现线上特有的问题。现在也提倡渐进式开发,让产品在迭代中快速成长。部署考验的不是你的 Django 编程水平,而是你对 Linux 的操作能力,以及对网络通信的理解。多说无益,直接开干!配置服务器要架设网站,首先你要有一台连接到互联网的服务器。国内比较出名的云服务器属阿里云、腾讯云、百度云,三家各有优劣,大家自行...
假设你的博客已经顺利部署到了线上。你写了很多好文章,和粉丝们互动并感受成就感。现在你想更进一步,努力提高文章质量,使其更受读者欢迎,打造圈内一流博客。问题是该如何判断一篇文章是“受欢迎的”?靠浏览量是个方法,但是并不能区分出内容花拳绣腿的标题党。靠评论数也是个好方法,但个人博客通常读者不多,好文章零评论是很正常的。这时候“点赞”功能就显得重要了。如果大部分读者都给了一个赞,那就表明文章确实还...
现在我们已经很熟悉Django的MTV模式了。模板(template)负责如何去展示数据,而视图(view)负责筛选出正确的数据。因此通常来说逻辑都是放到视图中的,但模板也需要一些和表示相关的逻辑:比如循环展示(如{% for ... %})、或者以某种特定格式输出(如{{ ...|date:'Y-m-d' }})等,这些功能都是靠模板的过滤器(filters)和标签(t...
上一章学习了自动化测试,很好,现在我们可以绞尽脑汁写出一份全面的测试,来保证代码永远健康了。话虽如此,但是作为一个独立开发者很难写出真正全面的测试代码。这是因为用户在使用你的网站时可不会循规蹈矩,而是会以各种怪异的姿势浏览网页、上传数据。但这也不是坏事,用户就是天然的测试人员,他们会很可爱的帮你找出一大堆的bug,陪你度过难眠的夜晚(伴随着编程能力的提升)。现在的问题是,开发者如何得知用户到...
测试是伴随着开发进行的,开发有多久,测试就要多久。本教程已经进行了30多章了,都是如何测试的?当然是runserver啦!每当开发新功能后,都需要运行服务器,假装自己就是用户,测试是否运行正常。这样的人工测试优点是非常直观,你看到的和用户看到的是完全相同的。但是缺点也很明显:效率低。在开发时可能你需要反复的修改代码、测试功能,这样重复查看几十次甚至几百次网页时会相当的让人烦躁。容易遗漏bug...