大家好,我是python222_小锋老师,分享一套优质的基于Python的在线音乐网站系统(后端Django) 。
项目简介
本文设计了一种基于Python的音乐播放网站,为人们提供了方便快捷、即用即搜的音乐搜索播放服务,包括音乐新闻、音乐交流、歌曲信息、歌曲排行、歌手排行等功能等,用户不仅能够方便快捷地查看音乐新闻、还能搜索自己喜爱的音乐歌曲进行播放等。音乐播放网站采取面对对象的开发模式进行软件的开发和硬体的架设,能很好的满足实际使用的需求,完善了对应的软体架设以及程序编码的工作,采用Python编程语言,MySQL数据库,Ajax异步交互,根据Ajax异步模式等开发工具,完成了系统的主要模块的页面设计和功能实现。本次报告,首先分析了研究的背景、作用、意义,为研究工作的合理性打下了基础。
源码下载
链接: pan.baidu.com/s/1x40DRLMP…
提取码: 1234
相关截图
核心代码
from django.shortcuts import render, redirect
from index.models import *
from user.models import *
from .form import MyUserCreationForm
from django.db.models import Q
from django.contrib.auth import login, logout
from django.contrib.auth.hashers import check_password
from django.contrib.auth.decorators import login_required
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
# 用户注册与登录
def loginView(request):
user = MyUserCreationForm()
# 表单提交
if request.method == 'POST':
# 判断表单提交是用户登录还是用户注册
# 用户登录
if request.POST.get('loginUser', ''):
loginUser = request.POST.get('loginUser', '')
password = request.POST.get('password', '')
if MyUser.objects.filter(Q(mobile=loginUser) | Q(username=loginUser)):
user = MyUser.objects.filter(Q(mobile=loginUser) | Q(username=loginUser)).first()
if check_password(password, user.password):
login(request, user)
return redirect('/user/home/1.html')
else:
tips = '密码错误'
else:
tips = '用户不存在'
# 用户注册
else:
user = MyUserCreationForm(request.POST)
if user.is_valid():
username = user.cleaned_data.get('username')
mobile = user.cleaned_data.get('mobile')
password1 = user.cleaned_data.get('password1')
password2 = user.cleaned_data.get('password2')
print(username)
print(mobile)
print(password1)
print(password2)
if password1 == password2:
user.save()
tips = '注册成功'
else:
if user.errors.get('username',''):
tips = user.errors.get('username','注册失败')
else:
tips = user.errors.get('mobile', '注册失败')
return render(request, 'user/login.html', locals())
# 用户中心
# 设置用户登录限制
@login_required(login_url='/user/login.html')
def homeView(request, page):
# 热搜歌曲
search_song = Dynamic.objects.select_related('song').order_by('-dynamic_search').all()[:4]
# 分页功能
song_info = request.session.get('play_list', [])
paginator = Paginator(song_info, 3)
try:
contacts = paginator.page(page)
except PageNotAnInteger:
contacts = paginator.page(1)
except EmptyPage:
contacts = paginator.page(paginator.num_pages)
return render(request, 'user/home.html', locals())
# 退出登录
def logoutView(request):
logout(request)
return redirect('/')