基于Django的电子商务网站开发(连载36)
- 2019 年 12 月 11 日
- 筆記
新年加入啄木鸟公众号,好运滚滚來!
顾翔老师开发的bugreport2script开源了,希望大家多提建议。文件在https://github.com/xianggu625/bug2testscript,
主文件是:zentao.py 。bugreport是禅道,script是python3+selenium 3,按照规则在禅道上书写的bugreport可由zentao.py程序生成py测试脚本。
3.8电子支付模块
电子支付模块包括使用支付宝、微信或其他手段进行支付,网上的资料已经很齐全了,读者也可以参阅参考文献【7】。
3.9建立自定义的错误页面
在这里我们主要介绍如何建立自定义的403、404、500错误页面,先建立403.html、404.html和500.html,分别如图3-21、图3-22、图3-23所示。

图3-21 403页面
403页面代码如下。
{%load staticfiles%}<head> <meta charset="UTF-8"> <title>403页面</title> <style type="text/css"> *{ margin: 0; padding: 0; background-color: #FFFFFFF; } div{ width: 700px; height: 200px; background-color: #FFFFFF; } .center-in-center{ position: absolute; top: 40%; left: 30%; } </style></head><body> <div> <img src="{%static 'image/403.JPG'%}" width="228" height="196">你没有这个权限!<br> <a href="/login_action/"><img src="{%static 'image/home.JPG'%}"></a> </div></body></html> |
---|

图3-22 404页面
404页面代码如下。
{%load staticfiles%}<head> <meta charset="UTF-8"> <title>404页面</title> <style type="text/css"> *{ margin: 0; padding: 0; background-color: #FFFFFFF; } div{ width: 700px; height: 200px; background-color: #FFFFFF; } .center-in-center{ position: absolute; top: 40%; left: 30%; } </style></head><body> <div> <img src="{%static 'image/404.JPG'%}" width="228" height="196">你的页面找不到了<br> 搜索你想要的或者刷新网页吧! <br> <img src="{%static 'image/reflesh.JPG'%}" onclick="location.reload(); "> </div></body></html> |
---|

图3-23 500页面
500页面代码如下。
{%load staticfiles%}<head> <meta charset="UTF-8"> <title>500页面</title> <style type="text/css"> *{ margin: 0; padding: 0; background-color: #FFFFFFF; } div{ width: 700px; height: 200px; background-color: #FFFFFF; } .center-in-center{ position: absolute; top: 40%; left: 30%; } </style></head><body> <div> <img src="{%static 'image/500.JPG'%}" width="228" height="196">服务器内部错误,不能执行这个请求! <br> <a href="/login_action/"><img src="{%static 'image/home.JPG'%}"></a></div></body></html> |
---|
然后打开settings.py,配置templates文件路径、关闭Debug、配置allowrd_hosts。
…DEBUG = False # 关闭Debug…TEMPLATES = [ { … 'DIRS': ['templates/'], # 配置templates文件路径 … },]…ALLOWED_HOSTS="*"… |
---|
最后在views.py中做如下的设置。
…from django.shortcuts import render def page_not_found(request): return render(request, '404.html') def page_error(request): return render(request, '500.html') def permission_denied(request):return render(request, '403.html')… |
---|
这样在页面显示403、404和500号错误的时候会显示对应自定义网页。
星云测试
http://www.teststars.cc
奇林软件
http://www.kylinpet.com
联合通测
http://www.quicktesting.net