Python django框架实现简单宠物商城
期末的课程设计,基于django框架的一个宠物商城,数据库使用的是sqlserver2019
登录注册代码
登录页面html <div class="login">
<div class="header">
<h2 style="color: #005980;">登录</h2>
<span class="register" style="font-color:#005980;">
没有账号?
<a href="/reg" style="text-decoration:none;cursor: pointer;color: #005980;">用户注册</a>
<a href="/sjreg" style="text-decoration:none;cursor: pointer;color: #005980;">商家注册</a>
</span>
</div>
<div id="loginbox">
<form action="" method="POST" name="login" id="main">
{% csrf_token %}
<div class="inputBox">
<div class="inputText">
<span class="iconfont icon-nickname"></span>
<input type="text" placeholder="Username" name="username" form="main" required/>
</div>
<div class="inputText">
<span class="iconfont icon-visible"></span>
<input type="password" placeholder="Password" name="password" form="main" required/>
{% if message %}
<div class="alert alert-warning">{{ message }}</div>
{% endif %}
</div>
</div>
<div class="check">
<input type="checkbox"/> 记住密码 <input type="checkbox" value="1" name="mg"/> 管理员登录<input type="checkbox" value="2" name="sh"/> 商家登录
</div>
<button type="submit" class="loginButton">login</button>
</form>
<div class="filed_center">
<a href="#">已有账号,忘记密码?</a>
</div>
<div class="rel">
--------------------------------
</div>
</div>
<span class="address">
中国·贵阳
</span>
</div>
</body>
</html>
登录界面可以选择三种登录方式,不选择为用户登录,管理员选择管理员登录,商家需要更新宠物选择商家登录
用户登录后可以查看所有宝贝,并且可以将需要的宝贝添加到购物车
购物车业务逻辑代码
def shopcar(request):
id=request.GET.get('id')
cursor = connection.cursor()
cursor.execute("delete from shopcar where Sid='{}'".format(id))
cursor.execute("select * from shopcar ")
rs = cursor.fetchall()
rlen = rs.__len__();
num = request.GET.get('num', 1);
num = int(num);
size = 10;
t = [];
page_max = int(math.ceil(rlen * 1.0 / size));
if (num <= 0):
num = 1;
if (num >= page_max):
num = page_max;
p_data = rs[((num - 1) * size):(num * size)];
for i in p_data:
s = Shopcar(sid=i[0], sname=i[1], sprice=i[2]);
t.append(s);
return render(request, 'shopcar.html', {'p_data': t})
需要完整源码的同学可以私我!