from django.shortcuts import render
from django.http import HttpResponse,JsonResponse
from myadmin.models import *
from django.contrib.auth.hashers import make_password, check_password
# Create your views here.
def index(request):
data = SType.objects.filter(pid=0)
for x in data:
x.sub = SType.objects.filter(path=x.id)
for y in x.sub:
y.sub = goods.objects.filter(typeid_id=y.id)
return render(request,'home/index.html',{"tlist":gettype(),"date":data})
def login(request):
if request.method == 'GET':
return render(request,'home/login.html')
elif request.method == 'POST':
print(request.POST)
res = request.POST
obj = User.objects.filter(phone=res['phone'])
if obj:
obj = obj[0]
if check_password(res['password'],obj.password):
request.session['VipUser'] = {'username':obj.username,"pic":obj.pic,"phone":obj.phone,"id":obj.id}
return HttpResponse('<script>alert("登陆成功!");location.href="/"</script>')
return HttpResponse('<script>alert("用户名或密码不正确!");location.href="/login/"</script>')
else:
return HttpResponse('<script>alert("请求方式不正确")</script>')
def loginout(request):
del request.session['VipUser']
return HttpResponse('<script>alert("退出成功!");location.href="/"</script>')
def register(request):
if request.method == 'GET':
return render(request,'home/register.html')
elif request.method == 'POST':
try:
obj = User()
obj.username = request.POST['phone'][0:3]+'vip用户'
obj.phone = request.POST['phone']
obj.password = make_password(request.POST['password'],None,"pbkdf2_sha256")
obj.save()
return HttpResponse('<script>alert("注册成功,跳转登陆!");location.href="/login/"</script>')
except:
return HttpResponse('<script>alert("注册失败,请重新尝试!");location.href="/register/"</script>')
else:
return HttpResponse('<script>alert("请求方式不正确!");location.href="/register/"</script>')
def personal(request):
try:
phone = request.session['VipUser']['phone']
print(phone)
obj = User.objects.get(phone=phone)
return render(request,'home/personal_info.html',{"date":obj})
except:
return HttpResponse('<script>alert("请先登陆!");location.href="/login/"</script>')
def user_edit(request):
if request.method == "GET":
uid = request.session["VipUser"]["id"]
date = User.objects.get(id = uid )
return render(request,'home/user_edit.html',{"date":date})
elif request.method == "POST":
uid = request.session["VipUser"]["id"]
from myadmin.views.views import picsave
r = picsave(request)
print(r)
if r == 101:
return HttpResponse('<script>alert("上传失败,错误代码101,文件格式不正确!请选择以下的文件格式:jpg,png,gif,ico");location.href="/user/edit"</script>')
elif r == 102:
return HttpResponse('<script>alert("上传失败,错误代码102,请检查网络连接,或者稍后进行上传!");location.href="/user/edit"</script>')
elif r == 103:
res = request.POST
obj = User.objects.get(id = uid)
obj.username=res['username']
obj.phone=res['phone']
obj.save()
return HttpResponse('<script>alert("上传成功,跳转到个人信息中心");location.href="/personal"</script>')
else:
res = request.POST
obj = User.objects.get(id = uid)
obj.username=res['username']
obj.phone=res['phone']
obj.pic=r
obj.save()
return HttpResponse('<script>alert("上传成功,跳转到个人信息中心");location.href="/personal"</script>')
def gettype():
date = SType.objects.filter(pid=0)
for x in date:
for y in SType.objects.filter(path=x.id):
x.sub = goods.objects.filter(typeid_id=y.id)
return date
def list(request):
uid = request.GET.get('id')
#获取商品级别
pid = SType.objects.get(id = uid).pid
if pid == 0:
# 得到总分类
date = SType.objects.filter(path=uid)
good = []
for x in date:
good += goods.objects.filter(typeid_id=x.id)
else:
#获取父类id
p = SType.objects.get(id=uid).path
date = SType.objects.filter(path = p)
# 获取商品
good =goods.objects.filter(typeid_id=uid)
print(date)
return render(request,'home/list.html',{"tlist":gettype(),"date":date,"good":good})
def desc(request):
rid = request.GET.get('id')
date = goods.objects.get(id = rid)
return render(request,'home/desc.html',{"date":date,"tlist":gettype()})
def cart(request):
try:
res = request.session.get('cart',{})
print(res)
if res:
date=[]
for x in res:
# print(res[x]['num'])
num = res[x]['num']
obj = goods.objects.get(id=int(x))
obj.num = num
date.append(obj)
print(date[0].__dict__)
print(date[0].price)
return render(request,'home/gouwucar.html',{"date":date,"tlist":gettype()})
else:
return render(request,'home/gouwucar.html',{"date":{},"tlist":gettype()})
except:
print('出错')
return render(request,'home/gouwucar.html')
# print(date)
def cart_add(request):
# print(request.session['cart'])
# try:
rid = request.GET['id']
num = request.GET['num']
res = goods.objects.get(id = rid )
cart = request.session.get('cart',{})
key = cart.keys()
if rid in key:
num=int(request.session['cart'][rid]["num"])+int(num)
date = {rid:{"gname":res.gname,"price":int(res.price),"num":num}}
request.session['cart'] = date
else:
date=cart
date[str(rid)]={"gname":res.gname,"price":int(res.price),"num":num}
request.session['cart'] = date
print("----------------")
print(request.session['cart'])
return HttpResponse(1)
# return JsonResponse(1,safe=False)
# except:
# return JsonResponse(2,safe=False)
def cart_del(request):
uid = request.GET['id']
res = request.session.get('cart',None)
try:
del request.session['cart'][uid]
date = request.session['cart']
request.session['cart'] = date
res = 0
except:
res = 1
return HttpResponse(res)
def cart_delall(request):
try:
del request.session['cart']
return HttpResponse('<script>alert("清空购物车成功!");location.href="/cart/"</script>')
except:
return HttpResponse('<script>alert("清空购物车成功!");location.href="/cart/"</script>')
def cart_editnum(request):
# 进行商品数量的修改,目的是为了防止用户刷新后数量的还原
datecart = request.session['cart']
gid = request.GET['gid']
num = request.GET['num']
datecart[gid]['num']=num
request.session["cart"]=datecart
print(datecart)
return HttpResponse("1")
#确认订单,需要的参数有,商品id列表,发送的参数有,用户地址和订单商品列表
def myorder(request):
if request.method == "GET":
ids = request.GET.get("ids",None)
if ids:
try:
k = ids.split(",")
order = {}
date = []
for x in k:
order[x] = request.session['cart'][x]
g = goods.objects.get(id=x)
g.num = order[x]["num"]
del request.session['cart'][x]
date.append(g)
# print(date)
request.session["order"] = order
request.session["cart"] = request.session["cart"]
# print(request.session["order"])
obj = address.objects.filter(uid=request.session["VipUser"]["id"])
return render(request,'home/myorder.html',{"date":obj,"res":date})
except:
return HttpResponse('<script>alert("商品订单生成失败!");location.href="/cart/"</script>')
else:
o = request.session.get("order",None)
if o:
date = request.session.get("order",None)
obj = address.objects.filter(uid=request.session["VipUser"]["id"])
return render(request,'home/myorder.html',{"date":obj,"res":date})
else:
return HttpResponse('<script>alert("商品获取失败!");location.href="/cart/"</script>')
elif request.method == "POST":
aid = request.POST.get("aid",None)
if aid:
uid = request.session["VipUser"]["id"]
good = request.session["order"]
sun = 0
num = 0
for x in good:
n = good[x]["num"]
price = good[x]["price"]
s = int(n)*int(price)
sun += s
num += int(n)
obj = Order()
obj.uid = User.objects.get(id = uid)
obj.aid = address.objects
没有合适的资源?快使用搜索试试~ 我知道了~
基于Django框架的在线商城系统设计源码
共980个文件
png:286个
jpg:279个
js:111个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 147 浏览量
2024-03-28
20:40:05
上传
评论
收藏 68.43MB ZIP 举报
温馨提示
这是一个基于Django框架的在线商城系统设计,使用Python语言开发,包含973个文件。主要文件类型包括286个PNG图片文件、279个JPG图片文件、111个JavaScript文件、72个CSS文件、64个HTML文件、47个GIF图片文件、33个Python字节码文件、26个Python源文件、13个map文件和6个SVG文件。该项目提供了一个完整的在线商城系统,支持商品分类添加、商品添加和账户管理等功能,适合用于电商网站的开发和部署。
资源推荐
资源详情
资源评论
收起资源包目录
基于Django框架的在线商城系统设计源码 (980个子文件)
amazeui.min.css 249KB
bootstrap.css 143KB
bootstrap.css 143KB
bootstrap.css 143KB
bootstrap.min.css 118KB
bootstrap.min.css 118KB
bootstrap.min.css 118KB
app.css 47KB
ueditor.css 43KB
ueditor.min.css 34KB
global.css 28KB
global.css 28KB
bootstrap-theme.css 26KB
bootstrap-theme.css 26KB
bootstrap-theme.css 26KB
bootstrap-theme.min.css 23KB
bootstrap-theme.min.css 23KB
bootstrap-theme.min.css 23KB
detail.css 23KB
detail.css 23KB
order.css 21KB
order.css 21KB
video-js.css 21KB
image.css 18KB
fullcalendar.min.css 15KB
video.css 15KB
app.css 14KB
app.css 14KB
attachment.css 14KB
video-js.min.css 11KB
register.css 9KB
register.css 9KB
font-awesome.css 9KB
amazeui.datatables.min.css 9KB
detail-app.css 9KB
detail-app.css 9KB
cart.css 9KB
cart.css 9KB
list.css 7KB
list.css 7KB
shCoreDefault.css 7KB
member.css 6KB
member.css 6KB
buy.css 6KB
circular.navigation.css 6KB
fullcalendar.print.css 5KB
gouwucar.css 5KB
index.css 5KB
admin.css 5KB
scrawl.css 4KB
list-app.css 4KB
list-app.css 4KB
codemirror.css 3KB
main.css 3KB
charts.css 3KB
background.css 2KB
reg.css 2KB
member-app.css 2KB
member-app.css 2KB
emotion.css 2KB
dialogbase.css 2KB
music.css 2KB
list.css 1KB
cart-app.css 1KB
cart-app.css 1KB
edittable.css 1KB
template.css 1KB
order-app.css 773B
order-app.css 773B
webuploader.css 515B
help.css 389B
iframe.css 41B
fontawesome-webfont.eot 75KB
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regular.eot 20KB
vjs.eot 3KB
UEditorSnapscreen.exe 508KB
wface.gif 49KB
jxface2.gif 40KB
yface.gif 28KB
bface.gif 27KB
icons.gif 20KB
file-icons.gif 20KB
file-icons.gif 20KB
tface.gif 19KB
fface.gif 18KB
cface.gif 8KB
icons-all.gif 4KB
videologo.gif 2KB
cancelbutton.gif 1KB
button-bg.gif 1KB
lock.gif 1KB
alignicon.gif 1KB
word.gif 1019B
icon_doc.gif 1012B
icon_psd.gif 1009B
icon_rar.gif 1007B
icon_xls.gif 1005B
icon_ppt.gif 1001B
共 980 条
- 1
- 2
- 3
- 4
- 5
- 6
- 10
资源评论
沐知全栈开发
- 粉丝: 5747
- 资源: 5215
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 适用于 DirectX 11 的延迟 PBR 渲染引擎.zip
- 程序设计基础1-8章-PPT.zip
- 适用于 delphi 的 DirectX GUI 框架 .zip
- 适用于 Delphi 和 Windows 的 3D 图形和游戏引擎 .zip
- 适用于 Blender 2.8+ 的 DirectX 模型导出器.zip
- 适用于 AMD GPU PerfStudio 工具的 DirectX 12 插件.zip
- 这是适用于 Windows 的一款小型截图工具,可以截取并保存 DirectX 游戏和其他应用程序的截图 还可以显示 FPS 和时间 .zip
- 话费提单系统,大猿人4.2支持余额查询,仅供学习,请勿商用
- 这是我的基于 DirectX 的 2D 游戏引擎 .zip
- Quartus开发的FPGA工程-ADC/DAC/频率计/外部触发
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功