parent
e9fac53a27
commit
55eec800c4
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class CommentConfig(AppConfig):
|
||||
name = 'comment'
|
||||
Binary file not shown.
@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
@ -0,0 +1,124 @@
|
||||
{% extends "title_base.html" %}
|
||||
{% load staticfiles %}
|
||||
|
||||
{% block header_extends %}
|
||||
<link type="image/x-icon" rel="shortcut icon" href="{% static 'favicon.ico' %}">
|
||||
<link type="text/css" rel="stylesheet" href="{% static 'css/common.css' %}">
|
||||
<link type="text/css" rel="stylesheet" href="{% static 'css/comment.css' %}">
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
<body class="review">
|
||||
<div class="header">
|
||||
<a href="/" class="logo" title="首页"><img alt="易点音乐" src="{% static 'image/logo.png' %}"></a>
|
||||
<div class="search-box">
|
||||
<form id="searchForm" action="{% url 'search' 1 %}" method="post" target="_blank">
|
||||
{% csrf_token %}
|
||||
<div class="search-keyword">
|
||||
<input id="kword" name="kword" type="text" class="keyword" maxlength="120" placeholder="音乐节" />
|
||||
</div>
|
||||
<input id="subSerch" type="submit" class="search-button" value="搜 索" />
|
||||
</form>
|
||||
<div id="suggest" class="search-suggest"></div>
|
||||
<div class="search-hot-words">
|
||||
{% for song in search_song %}
|
||||
<a target="play" href="{% url 'play' song.song.song_id %}" >{{ song.song.song_name }}</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div><!--end header-->
|
||||
<div class="nav-box">
|
||||
<div class="nav-box-inner">
|
||||
<ul class="nav clearfix">
|
||||
<li><a href="/">首页</a></li>
|
||||
<li><a href="{% url 'ranking' %}" target="_blank">歌曲排行</a></li>
|
||||
<li><a href="{% url 'home' 1 %}" target="_blank">用户中心</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div><!--end nav-box-->
|
||||
<div class="wrapper">
|
||||
<div class="breadcrumb">
|
||||
<a href="/">首页</a> >
|
||||
<a href="{% url 'play' song_id %}" target="_self">{{song_name}}</a> >
|
||||
<span>点评</span>
|
||||
</div>
|
||||
<div class="page-title" id="currentSong"></div>
|
||||
</div>
|
||||
<div class="wrapper">
|
||||
<div class="section">
|
||||
<div class="section-header"><h3 class="section-title">网友点评</h3></div>
|
||||
<div class="section-content comments-score-new review-comments-score clearfix">
|
||||
<div class="clearfix">
|
||||
|
||||
<!--点评框-->
|
||||
<div class="comments-box">
|
||||
<div class="comments-box-title">我要点评<<{{ song_name }}>></div>
|
||||
<div class="comments-default-score clearfix"></div>
|
||||
<form action="" method="post" id="usrform">
|
||||
{% csrf_token %}
|
||||
<div class="writebox">
|
||||
<textarea name="comment" form="usrform"></textarea>
|
||||
</div>
|
||||
<div class="comments-box-button clearfix">
|
||||
<input type="submit" value="发布" class="_j_cc_post_entry cc-post-entry" id="scoreBtn">
|
||||
<div data-role="user-login" class="_j_cc_post_login"></div>
|
||||
</div>
|
||||
<div id="scoreTips2" style="padding-top:10px;"></div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="wrapper clearfix">
|
||||
<div class="content">
|
||||
<div id="J_CommentList">
|
||||
<ul class="comment-list">
|
||||
{% for item in contacts.object_list %}
|
||||
<li class="comment-item ">
|
||||
<div class="comments-user">
|
||||
<span class="face">
|
||||
<img src="{% static 'image/user.jpg' %}" width="60" height="60">
|
||||
</span>
|
||||
</div>
|
||||
<div class="comments-list-content">
|
||||
<div class="single-score clearfix">
|
||||
<span class="date">{{ item.comment_date }}</span>
|
||||
<div><span class="score">{{ item.comment_user }}</span></div>
|
||||
</div>
|
||||
<!--comments-content-->
|
||||
<div class="comments-content">
|
||||
<div class="J_CommentContent comment-height-limit">
|
||||
<div class="content-inner">
|
||||
<div class="comments-words">
|
||||
<p>{{ item.comment_text }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<div class="page-box">
|
||||
<div class="pagebar" id="pageBar">
|
||||
{% if contacts.has_previous %}
|
||||
<a href="{% url 'comment' song_id %}?page={{ contacts.previous_page_number }}" class="prev" target="_self"><i></i>上一页</a>
|
||||
{% endif %}
|
||||
{% for page in contacts.paginator.page_range %}
|
||||
{% if contacts.number == page %}
|
||||
<span class="sel">{{ page }}</span>
|
||||
{% else %}
|
||||
<a href="{% url 'comment' song_id %}?page={{ page }}" target="_self">{{ page }}</a>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if contacts.has_next %}
|
||||
<a href="{% url 'comment' song_id %}?page={{ contacts.next_page_number }}" class="next" target="_self">下一页<i></i></a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
@ -0,0 +1,22 @@
|
||||
"""music URL Configuration
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/2.0/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.urls import include, path
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.urls import path
|
||||
|
||||
from comment.views import CommentView
|
||||
|
||||
urlpatterns = [
|
||||
path('<int:song_id>', CommentView.as_view(), name='comment'),
|
||||
]
|
||||
@ -0,0 +1,41 @@
|
||||
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
||||
from django.shortcuts import render, redirect
|
||||
from django.http import Http404
|
||||
from django.views import View
|
||||
|
||||
from index.models import *
|
||||
import time
|
||||
|
||||
|
||||
class CommentView(View):
|
||||
def post(self, request, song_id):
|
||||
# 点评提交处理
|
||||
comment_text = request.POST.get('comment', '')
|
||||
comment_user = request.user.username if request.user.username else '匿名用户'
|
||||
if comment_text:
|
||||
comment = Comment()
|
||||
comment.comment_text = comment_text
|
||||
comment.comment_user = comment_user
|
||||
comment.comment_date = time.strftime('%Y-%m-%d', time.localtime(time.time()))
|
||||
comment.song_id = song_id
|
||||
comment.save()
|
||||
return redirect('/comment/%s' % song_id)
|
||||
|
||||
def get(self, request, song_id):
|
||||
# 热搜歌曲
|
||||
search_song = Dynamic.objects.select_related('song').order_by('-dynamic_search').all()[:6]
|
||||
song_info = Song.objects.filter(song_id=song_id).first()
|
||||
# 歌曲不存在抛出404异常
|
||||
if not song_info:
|
||||
raise Http404
|
||||
comment_all = Comment.objects.filter(song_id=song_id).order_by('comment_date')
|
||||
song_name = song_info.song_name
|
||||
page = int(request.GET.get('page', 1))
|
||||
paginator = Paginator(comment_all, 2)
|
||||
try:
|
||||
contacts = paginator.page(page)
|
||||
except PageNotAnInteger:
|
||||
contacts = paginator.page(1)
|
||||
except EmptyPage:
|
||||
contacts = paginator.page(paginator.num_pages)
|
||||
return render(request, 'comment.html', locals())
|
||||
@ -0,0 +1,16 @@
|
||||
from django.apps import AppConfig
|
||||
import os
|
||||
import pymysql
|
||||
pymysql.install_as_MySQLdb()
|
||||
# 修改app在Admin后台显示名称
|
||||
# default_app_config的值来自apps.py的类名
|
||||
default_app_config = 'index.IndexConfig'
|
||||
|
||||
# 获取当前app的命名
|
||||
def get_current_app_name(_file):
|
||||
return os.path.split(os.path.dirname(_file))[-1]
|
||||
|
||||
# 重写类IndexConfig
|
||||
class IndexConfig(AppConfig):
|
||||
name = get_current_app_name(__file__)
|
||||
verbose_name = '网站首页'
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class IndexConfig(AppConfig):
|
||||
name = 'index'
|
||||
@ -0,0 +1,75 @@
|
||||
# Generated by Django 2.2.5 on 2019-09-11 07:37
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Label',
|
||||
fields=[
|
||||
('label_id', models.AutoField(primary_key=True, serialize=False, verbose_name='序号')),
|
||||
('label_name', models.CharField(max_length=10, verbose_name='分类标签')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': '歌曲分类',
|
||||
'verbose_name_plural': '歌曲分类',
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Song',
|
||||
fields=[
|
||||
('song_id', models.AutoField(primary_key=True, serialize=False, verbose_name='序号')),
|
||||
('song_name', models.CharField(max_length=50, verbose_name='歌名')),
|
||||
('song_singer', models.CharField(max_length=50, verbose_name='歌手')),
|
||||
('song_time', models.CharField(max_length=10, verbose_name='时长')),
|
||||
('song_album', models.CharField(max_length=100, verbose_name='专辑')),
|
||||
('song_languages', models.CharField(max_length=20, verbose_name='语种')),
|
||||
('song_company', models.CharField(max_length=50, verbose_name='唱片公司')),
|
||||
('song_release', models.CharField(max_length=20, verbose_name='发行时间')),
|
||||
('song_img', models.CharField(max_length=20, verbose_name='歌曲图片')),
|
||||
('song_lyrics', models.CharField(default='暂无歌词', max_length=50, verbose_name='歌词')),
|
||||
('song_file', models.CharField(max_length=50, verbose_name='歌曲文件')),
|
||||
('label', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='index.Label', verbose_name='歌名分类')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': '歌曲信息',
|
||||
'verbose_name_plural': '歌曲信息',
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Dynamic',
|
||||
fields=[
|
||||
('dynamic_id', models.AutoField(primary_key=True, serialize=False, verbose_name='序号')),
|
||||
('dynamic_plays', models.IntegerField(verbose_name='播放次数')),
|
||||
('dynamic_search', models.IntegerField(verbose_name='搜索次数')),
|
||||
('dynamic_down', models.IntegerField(verbose_name='下载次数')),
|
||||
('song', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='index.Song', verbose_name='歌名')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': '歌曲动态',
|
||||
'verbose_name_plural': '歌曲动态',
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Comment',
|
||||
fields=[
|
||||
('comment_id', models.AutoField(primary_key=True, serialize=False, verbose_name='序号')),
|
||||
('comment_text', models.CharField(max_length=500, verbose_name='内容')),
|
||||
('comment_user', models.CharField(max_length=20, verbose_name='用户')),
|
||||
('comment_date', models.CharField(max_length=50, verbose_name='日期')),
|
||||
('song', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='index.Song', verbose_name='歌名')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': '歌曲评论',
|
||||
'verbose_name_plural': '歌曲评论',
|
||||
},
|
||||
),
|
||||
]
|
||||
Binary file not shown.
Binary file not shown.
@ -0,0 +1,68 @@
|
||||
from django.db import models
|
||||
|
||||
|
||||
# 歌曲分类表label
|
||||
class Label(models.Model):
|
||||
label_id = models.AutoField('序号', primary_key=True)
|
||||
label_name = models.CharField('分类标签', max_length=10)
|
||||
|
||||
def __str__(self):
|
||||
return self.label_name
|
||||
|
||||
class Meta:
|
||||
# 设置Admin界面的显示内容
|
||||
verbose_name = '歌曲分类'
|
||||
verbose_name_plural = '歌曲分类'
|
||||
|
||||
|
||||
# 歌曲信息表song
|
||||
class Song(models.Model):
|
||||
song_id = models.AutoField('序号', primary_key=True)
|
||||
song_name = models.CharField('歌名', max_length=50)
|
||||
song_singer = models.CharField('歌手', max_length=50)
|
||||
song_time = models.CharField('时长', max_length=10)
|
||||
song_album = models.CharField('专辑', max_length=100)
|
||||
song_languages = models.CharField('语种', max_length=20)
|
||||
song_company = models.CharField('唱片公司', max_length=50)
|
||||
song_release = models.CharField('发行时间', max_length=20)
|
||||
song_img = models.CharField('歌曲图片', max_length=20)
|
||||
song_lyrics = models.CharField('歌词', max_length=50, default='暂无歌词')
|
||||
song_file = models.CharField('歌曲文件', max_length=50)
|
||||
label = models.ForeignKey(Label, on_delete=models.CASCADE, verbose_name='歌名分类')
|
||||
|
||||
def __str__(self):
|
||||
return self.song_name
|
||||
|
||||
class Meta:
|
||||
# 设置Admin界面的显示内容
|
||||
verbose_name = '歌曲信息'
|
||||
verbose_name_plural = '歌曲信息'
|
||||
|
||||
|
||||
# 歌曲动态表dynamic
|
||||
class Dynamic(models.Model):
|
||||
dynamic_id = models.AutoField('序号', primary_key=True)
|
||||
song = models.ForeignKey(Song, on_delete=models.CASCADE, verbose_name='歌名')
|
||||
dynamic_plays = models.IntegerField('播放次数')
|
||||
dynamic_search = models.IntegerField('搜索次数')
|
||||
dynamic_down = models.IntegerField('下载次数')
|
||||
|
||||
class Meta:
|
||||
# 设置Admin界面的显示内容
|
||||
verbose_name = '歌曲动态'
|
||||
verbose_name_plural = '歌曲动态'
|
||||
|
||||
|
||||
# 歌曲点评表comment
|
||||
class Comment(models.Model):
|
||||
comment_id = models.AutoField('序号', primary_key=True)
|
||||
comment_text = models.CharField('内容', max_length=500)
|
||||
comment_user = models.CharField('用户', max_length=20)
|
||||
song = models.ForeignKey(Song, on_delete=models.CASCADE, verbose_name='歌名')
|
||||
comment_date = models.CharField('日期', max_length=50)
|
||||
|
||||
class Meta:
|
||||
# 设置Admin界面的显示内容
|
||||
verbose_name = '歌曲评论'
|
||||
verbose_name_plural = '歌曲评论'
|
||||
# Create your models here.
|
||||
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
@ -0,0 +1,24 @@
|
||||
from django.shortcuts import render
|
||||
from .models import *
|
||||
|
||||
|
||||
def IndexView(request):
|
||||
# 热搜歌曲
|
||||
search_song = Dynamic.objects.select_related('song').order_by('-dynamic_search').all()[:8]
|
||||
# 音乐分类
|
||||
label_list = Label.objects.all()
|
||||
# 热门歌曲
|
||||
play_hot_song = Dynamic.objects.select_related('song').order_by('-dynamic_plays').all()[:10]
|
||||
# 新歌推荐
|
||||
daily_recommendation = Song.objects.order_by('-song_release').all()[:3]
|
||||
# 热门搜索、热门下载
|
||||
search_ranking = search_song[:6]
|
||||
down_ranking = Dynamic.objects.select_related('song').order_by('-dynamic_down').all()[:6]
|
||||
all_ranking = [search_ranking, down_ranking]
|
||||
return render(request, 'index.html', locals())
|
||||
|
||||
|
||||
# 自定义404和500的错误页面
|
||||
def page_not_found(request):
|
||||
return render(request, 'error404.html', status=404)
|
||||
# Create your views here.
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env python
|
||||
"""Django's command-line utility for administrative tasks."""
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'music.settings')
|
||||
try:
|
||||
from django.core.management import execute_from_command_line
|
||||
except ImportError as exc:
|
||||
raise ImportError(
|
||||
"Couldn't import Django. Are you sure it's installed and "
|
||||
"available on your PYTHONPATH environment variable? Did you "
|
||||
"forget to activate a virtual environment?"
|
||||
) from exc
|
||||
execute_from_command_line(sys.argv)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@ -0,0 +1,2 @@
|
||||
import pymysql
|
||||
pymysql.install_as_MySQLdb()
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,16 @@
|
||||
"""
|
||||
WSGI config for music project.
|
||||
|
||||
It exposes the WSGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'music.settings')
|
||||
|
||||
application = get_wsgi_application()
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class PlayConfig(AppConfig):
|
||||
name = 'play'
|
||||
Binary file not shown.
@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
@ -0,0 +1,24 @@
|
||||
"""music URL Configuration
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/2.0/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.urls import include, path
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
# 歌曲播放页面
|
||||
path('<int:song_id>', views.playView, name='play'),
|
||||
# 歌曲下载
|
||||
path('download/<int:song_id>.mp3', views.downloadView, name='download')
|
||||
]
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class RankingConfig(AppConfig):
|
||||
name = 'ranking'
|
||||
Binary file not shown.
@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
@ -0,0 +1,99 @@
|
||||
{% extends "title_base.html" %}
|
||||
{% load staticfiles %}
|
||||
{% block header_extends %}
|
||||
<link type="image/x-icon" rel="shortcut icon" href="{% static 'favicon.ico' %}">
|
||||
<link type="text/css" rel="stylesheet" href="{% static 'css/common.css' %}">
|
||||
<link type="text/css" rel="stylesheet" href="{% static 'css/ranking.css' %}">
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
<body>
|
||||
<div class="header">
|
||||
<a href="/" class="logo" title="首页"><img alt="我的音乐" src="{% static 'image/logo.png' %}"></a>
|
||||
<div class="search-box">
|
||||
<form id="searchForm" action="{% url 'search' 1 %}" method="post" target="_blank">
|
||||
{% csrf_token %}
|
||||
<div class="search-keyword">
|
||||
<input name="kword" type="text" class="keyword" maxlength="120" placeholder="音乐节" />
|
||||
</div>
|
||||
<input id="subSerch" type="submit" class="search-button" value="搜 索" />
|
||||
</form>
|
||||
<div id="suggest" class="search-suggest"></div>
|
||||
<div class="search-hot-words">
|
||||
{% for song in search_song %}
|
||||
<a target="play" href="{% url 'play' song.song.song_id %}" >{{ song.song.song_name }}</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div><!--end header-->
|
||||
<div class="nav-box">
|
||||
<div class="nav-box-inner">
|
||||
<ul class="nav clearfix">
|
||||
<li><a href="/">首页</a></li>
|
||||
<li><a href="{% url 'ranking' %}">歌曲排行</a></li>
|
||||
<li><a href="{% url 'home' 1 %}" target="_blank">用户中心</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div><!--end nav-box-->
|
||||
<div class="wrapper clearfix">
|
||||
<!-- 左侧列表 -->
|
||||
<div class="side">
|
||||
<!-- 子类分类排行导航 -->
|
||||
<div class="side-nav">
|
||||
<div class="nav-head">
|
||||
<a href="{% url 'ranking' %}">所有歌曲分类</a>
|
||||
</div>
|
||||
<ul id="sideNav" class="cate-item">
|
||||
{% for item in All_list %}
|
||||
<li class="computer">
|
||||
<div class="main-cate">
|
||||
<a href="{% url 'ranking' %}?type={{ item.song_company }}" class="main-title">{{ item.song_company }}</a>
|
||||
</div>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</div><!-- 左侧列表 end -->
|
||||
|
||||
<div class="main">
|
||||
<div class="main-head-box clearfix">
|
||||
<div class="main-head"><h1>歌曲排行榜</h1></div>
|
||||
</div>
|
||||
<table class="rank-list-table">
|
||||
<tr>
|
||||
<th class="cell-1">排名</th>
|
||||
<th class="cell-2">图片</th>
|
||||
<th class="cell-3">歌名</th>
|
||||
<th class="cell-4">专辑</th>
|
||||
<th class="cell-5">下载量</th>
|
||||
<th class="cell-6">播放量</th>
|
||||
</tr>
|
||||
{% for item in song_info %}
|
||||
<tr>
|
||||
{%if forloop.counter < 4 %}
|
||||
<td><span class="n1">{{forloop.counter}}</span></td>
|
||||
{%else %}
|
||||
<td><span class="n2">{{forloop.counter}}</span></td>
|
||||
{%endif %}
|
||||
<td>
|
||||
<a href="{% url 'play' item.song.song_id %}" class="pic" target="play"><img src="{% static 'songImg/' %}{{ item.song.song_img }}" width="80" height="80"></a>
|
||||
</td>
|
||||
<td class="name-cell">
|
||||
<h3><a href="{% url 'play' item.song.song_id %}" target="play" >{{item.song.song_name}}</a></h3>
|
||||
<div class="desc">
|
||||
<a href="javascript:;" target="_blank" class="type" >{{item.song.song_singer}}</a>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div style="text-align:center;">{{item.song.song_album}}</div>
|
||||
</td>
|
||||
<td>
|
||||
<div style="text-align:center;">{{item.dynamic_down}}</div>
|
||||
</td>
|
||||
<td class="num-cell">{{item.dynamic_plays}}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<script data-main="{% static 'js/ranking.js' %}" src="{% static 'js/require.js' %}"></script>
|
||||
{% endblock %}
|
||||
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
@ -0,0 +1,22 @@
|
||||
"""music URL Configuration
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/2.0/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.urls import include, path
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.urls import path
|
||||
from . import views
|
||||
urlpatterns = [
|
||||
path('', views.rankingView, name='ranking'),
|
||||
# 通用视图
|
||||
# path('.list', views.RankingList.as_view(), name='rankingList'),
|
||||
]
|
||||
@ -0,0 +1,49 @@
|
||||
from django.shortcuts import render
|
||||
from index.models import *
|
||||
|
||||
|
||||
def rankingView(request):
|
||||
# 搜索歌曲
|
||||
search_song = Dynamic.objects.select_related('song').order_by('-dynamic_search').all()[:4]
|
||||
# 歌曲分类列表
|
||||
All_list = Song.objects.values('song_company').distinct()
|
||||
# 歌曲列表信息
|
||||
song_company = request.GET.get('type', '')
|
||||
if song_company:
|
||||
song_info = Dynamic.objects.select_related('song').filter(song__song_company=song_company).order_by(
|
||||
'-dynamic_plays').all()[:10]
|
||||
else:
|
||||
song_info = Dynamic.objects.select_related('song').order_by('-dynamic_plays').all()[:10]
|
||||
return render(request, 'ranking.html', locals())
|
||||
|
||||
|
||||
# #通用视图
|
||||
# from django.views.generic import ListView
|
||||
#
|
||||
#
|
||||
# class RankingList(ListView):
|
||||
# # context_object_name设置Html模版的某一个变量名称
|
||||
# context_object_name = 'song_info'
|
||||
# # 设定模版文件
|
||||
# template_name = 'ranking.html'
|
||||
#
|
||||
# # 查询变量song_info的数据
|
||||
# def get_queryset(self):
|
||||
# # 获取请求参数
|
||||
# song_company = self.request.GET.get('type', '')
|
||||
# if song_company:
|
||||
# song_info = Dynamic.objects.select_related('song').filter(song__song_company=song_company).order_by(
|
||||
# '-dynamic_plays').all()[:10]
|
||||
# else:
|
||||
# song_info = Dynamic.objects.select_related('song').order_by('-dynamic_plays').all()[:10]
|
||||
# return song_info
|
||||
#
|
||||
# # 添加其他变量
|
||||
# def get_context_data(self, **kwargs):
|
||||
# context = super().get_context_data(**kwargs)
|
||||
# # 搜索歌曲
|
||||
# context['search_song'] = Dynamic.objects.select_related('song').order_by('-dynamic_search').all()[:4]
|
||||
# # 所有歌曲分类
|
||||
# context['All_list'] = Song.objects.values('song_company').distinct()
|
||||
# return context
|
||||
# # Create your views here.
|
||||
@ -0,0 +1,7 @@
|
||||
Django==2.2.5
|
||||
lxml==4.0.0
|
||||
PyMySQL==0.9.3
|
||||
requests==2.23.0
|
||||
sqlparse==0.3.1
|
||||
urllib3==1.25.9
|
||||
uWSGI==2.0.18
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class SearchConfig(AppConfig):
|
||||
name = 'search'
|
||||
Binary file not shown.
@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
@ -0,0 +1,85 @@
|
||||
{% extends "title_base.html" %}
|
||||
{% load staticfiles %}
|
||||
{% block header_extends %}
|
||||
<link type="image/x-icon" rel="shortcut icon" href="{% static 'favicon.ico' %}">
|
||||
<link type="text/css" rel="stylesheet" href="{% static 'css/common.css' %}">
|
||||
<link type="text/css" rel="stylesheet" href="{% static 'css/search.css' %}">
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
<body>
|
||||
<div class="header">
|
||||
<a href="/" class="logo" title="首页"><img alt="我的音乐" src="{% static 'image/logo.png' %}"></a>
|
||||
<div class="search-box">
|
||||
<form id="searchForm" action="{% url 'search' 1 %}" method="post" target="_blank">
|
||||
{% csrf_token %}
|
||||
<div class="search-keyword">
|
||||
<input id="kword" name="kword" type="text" class="keyword" maxlength="120" placeholder="音乐节" />
|
||||
</div>
|
||||
<input id="subSerch" type="submit" class="search-button" value="搜 索" />
|
||||
</form>
|
||||
<div id="suggest" class="search-suggest"></div>
|
||||
<div class="search-hot-words">
|
||||
{% for song in search_song %}
|
||||
<a target="play" href="{% url 'play' song.song.song_id %}" >{{ song.song.song_name }}</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div><!--end header-->
|
||||
<div class="nav-box">
|
||||
<div class="nav-box-inner">
|
||||
<ul class="nav clearfix">
|
||||
<li><a href="/">首页</a></li>
|
||||
<li><a href="{% url 'ranking' %}" target="_blank">歌曲排行</a></li>
|
||||
<li><a href="{% url 'home' 1 %}" target="_blank">用户中心</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div><!--end nav-box-->
|
||||
<!--wrapper-->
|
||||
<div class="wrapper clearfix" id="wrapper">
|
||||
<div class="mod_songlist">
|
||||
<ul class="songlist__header">
|
||||
<li class="songlist__header_name">歌曲</li>
|
||||
<li class="songlist__header_author">歌手</li>
|
||||
<li class="songlist__header_time">时长</li>
|
||||
</ul>
|
||||
<ul class="songlist__list">
|
||||
{%for list in contacts.object_list %}
|
||||
<li class="js_songlist__child">
|
||||
<div class="songlist__item">
|
||||
<div class="songlist__songname">
|
||||
<span class="songlist__songname_txt">
|
||||
<a href="{% url 'play' list.song_id %}" class="js_song" target="play" >{{list.song_name}}</a>
|
||||
</span>
|
||||
</div>
|
||||
<div class="songlist__artist">
|
||||
<a href="javascript:;" class="singer_name" >{{list.song_singer}}</a>
|
||||
</div>
|
||||
<div class="songlist__time">{{list.song_time}}</div>
|
||||
</div>
|
||||
</li>
|
||||
{%endfor %}
|
||||
</ul>
|
||||
<div class="page-box">
|
||||
<div class="pagebar" id="pageBar">
|
||||
{% if contacts.has_previous %}
|
||||
<a href="{% url 'search' contacts.previous_page_number %}" class="prev" target="_self"><i></i>上一页</a>
|
||||
{% endif %}
|
||||
|
||||
{% for page in contacts.paginator.page_range %}
|
||||
{% if contacts.number == page %}
|
||||
<span class="sel">{{ page }}</span>
|
||||
{% else %}
|
||||
<a href="{% url 'search' page %}" target="_self">{{ page }}</a>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% if contacts.has_next %}
|
||||
<a href="{% url 'search' contacts.next_page_number %}" class="next" target="_self">下一页<i></i></a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div><!--end mod_songlist-->
|
||||
</div><!--end wrapper-->
|
||||
<!--footer-->
|
||||
|
||||
{% endblock %}
|
||||
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue