main
syk1209wwz0306 6 months ago
parent 1ab05b90f4
commit 8d4d7669f4

@ -8,8 +8,6 @@ app_name = 'movie'
urlpatterns = [
# 默认首页
path('', views.IndexView.as_view(), name='index'),
# 分类查看
path('tag', views.TagView.as_view(), name='tag'),
# 电影详情页面
path('detail/<int:pk>', views.MovieDetailView.as_view(), name='detail'),

@ -50,17 +50,8 @@ class IndexView(ListView):
'right_has_more': right_has_more
}
# 电影分类视图
class TagView(ListView):
model = Movie
template_name = 'movie/tag.html'
paginate_by = 15
context_object_name = 'movies'
page_kwarg = 'p'
def get_queryset(self):
tag_slug = self.kwargs.get('slug') # 假设URL中传入了分类的slug
return Movie.objects.filter(tag=tag_slug).order_by('id')
# 电影详情视图
class MovieDetailView(DetailView):

@ -11,8 +11,34 @@
<script src="http://cdn.bootcss.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
</head>
<body>
<!-- 导航条代码保持不变 -->
<!-- 导航条 -->
<nav class="navbar navbar-default navbar-static-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="{% url 'movie:index' %}">Django电影推荐系统</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<!-- 搜索框 -->
<form class="navbar-form navbar-left" method="GET" action="{% url 'movie:search' %}">
<div class="form-group">
<input type="search" name="keyword" class="form-control" placeholder="请输入电影信息" required>
</div>
<button type="submit" class="btn btn-default">搜索电影</button>
</form>
<!-- 导航链接和其他组件放在这里 -->
</div>
</div>
</nav>
<!-- 主体内容 -->
{% block content %}
<div class="container">
<div class="jumbotron">
@ -40,14 +66,6 @@
</nav>
{% endblock %}
<div class="mastfoot" style="text-align: center;margin-top:50px;margin-bottom: 30px">
<div class="inner">
<p>
<span>Copyright (C). create by BHML 2023, All Rights Reserved</span>&nbsp;&nbsp;
</p>
</div>
</div>
<!-- 页面底部 -->
</body>
</html>

@ -29,10 +29,7 @@
<p>编剧:{{ movie.writers }}</p>
<p>主演:{{ movie.actors }}</p>
<p>
类型:
{% for genre in movie.get_genre %}
<a href="{% url 'movie:tag' %}?genre={{ genre }}">{{ genre }}</a>{% if not forloop.last %} | {% endif %}
{% endfor %}
</p>
<p>时长:{{ movie.time }}</p>
<p>发行时间:{{ movie.release_time }}</p>

@ -1,7 +1,6 @@
{% extends "movie/base.html" %}
{% load static %} <!-- 确保加载static标签 -->
{% block content %}
<style>
<style>
.item {
display: block;
float: left;
@ -15,52 +14,72 @@
height: 320px;
overflow: hidden;
}
</style>
<div class="container">
</style>
<div class="container">
<div class="jumbotron">
<h1>项目简介</h1>
<p>电影推荐系统</p>
<!-- 其他简介内容 -->
<p>数据集本系统使用最新的movielens数据集版本ml-latest-small该数据集该数据集包含9742部电影、
610个用户、100837个评分。有 links.csv (电影的imdbid和tmdbid)、 movies.csv (电影详情)、 ratings.csv (电影评分数据集 )等数据。
</p>
<p>系统首页会展示部分电影热门电影会展示评分最高的前100部电影你可以点击任意一部电影查看详情</p>
<p>你可以给电影评分(需登录),查看网站对你的推荐(基于用户的协同过滤算法)</p>
<p>使用分类或搜索功能可以帮助你找到电影</p>
</div>
</div>
</div>
<!--展示电影图片用-->
<div class="container">
<div class="container">
<!-- 展示电影图片 -->
{% for movie in movies %}
<a href="{% url 'movie:detail' movie.pk %}" class="item">
<div class="poster_div">
<img src="/static/movie/poster/{{ movie.imdb_id }}.jpg" alt="">
<p>{{ movie.name }}
<strong style="color:#e09015">{{ movie.get_score }}</strong>
</p>
</div>
</a>
{% endfor %}
</div>
</div>
<!-- 分页导航 -->
<nav style="text-align: center;">
<!-- nav视图分页用 不用管-->
<nav style="text-align: center;">
<ul class="pagination">
{#previous page#}
{% if page_obj.has_previous %}
<li><a href="?p={{ page_obj.previous_page_number }}">上一页</a></li>
<li><a href="{% url 'movie:index' %}?p={{ page_obj.previous_page_number }}">上一页</a></li>
{% else %}
<li class="disabled"><span>上一页</span></li>
<li class="disabled"><a href="javascript:void(0);">上一页</a></li>
{% endif %}
{% for num in paginator.page_range %}
{% if num == page_obj.number %}
<li class="active"><span>{{ num }}</span></li>
{% elif num > page_obj.number|add:-3 and num < page_obj.number|add:3 %}
<li><a href="?p={{ num }}">{{ num }}</a></li>
{% if left_has_more %}
<li><a href="{% url 'movie:index' %}?p=1">1</a></li>
<li><a href="javascript:void(0)">...</a></li>
{% endif %}
{# 左边的page#}
{% for left_page in left_pages %}
<li><a href="{% url 'movie:index' %}?p={{ left_page }}">{{ left_page }}</a></li>
{% endfor %}
{# 当前的page#}
<li class="active"><a href="javascript:void(0);">{{ current_page }}</a></li>
{# 右边的page#}
{% for right_page in right_pages %}
<li><a href="{% url 'movie:index' %}?p={{ right_page }}">{{ right_page }}</a></li>
{% endfor %}
{% if right_has_more %}
<li><a href="javascript:void(0)">...</a></li>
<li><a href="{% url 'movie:index' %}?p={{ paginator.num_pages }}">{{ paginator.num_pages }}</a></li>
{% endif %}
{#next page#}
{% if page_obj.has_next %}
<li><a href="?p={{ page_obj.next_page_number }}">下一页</a></li>
<li><a href="{% url 'movie:index' %}?p={{ page_obj.next_page_number }}">下一页</a></li>
{% else %}
<li class="disabled"><span>下一页</span></li>
<li class="disabled"><a href="javascript:void(0);">上一页</a></li>
{% endif %}
</ul>
</nav>
</nav>
{% endblock %}

@ -1,114 +0,0 @@
{% extends 'movie/base.html' %}
{% block content %}
<style>
.item_ {
display: block;
float: left;
font-size: 15px;
text-align: center;
margin: 0 25px 10px 0;
width: 200px;
}
.item_ .poster_div {
height: 320px;
overflow: hidden;
}
.li_ li {
height: 45px;
width: 115px;
}
.{{ genre }} {
}
</style>
<div class="container">
<ul class="nav nav-pills li_">
<li role="presentation" class="active"><a href="#">类型</a></li>
<li role="presentation" class="Musical"><a href="{% url 'movie:tag' %}?genre=Musical">Musical</a></li>
<li role="presentation" class="War"><a href="{% url 'movie:tag' %}?genre=War">War</a></li>
<li role="presentation" class="Crime"><a href="{% url 'movie:tag' %}?genre=Crime">Crime</a></li>
<li role="presentation" class="Romance"><a href="{% url 'movie:tag' %}?genre=Romance">Romance</a></li>
<li role="presentation" class="Fantasy"><a href="{% url 'movie:tag' %}?genre=Fantasy">Fantasy</a></li>
<li role="presentation" class="Drama"><a href="{% url 'movie:tag' %}?genre=Drama">Drama</a></li>
<li role="presentation" class="Music"><a href="{% url 'movie:tag' %}?genre=Music">Music</a></li>
<li role="presentation" class="Sci-Fi"><a href="{% url 'movie:tag' %}?genre=Sci-Fi">Sci-Fi</a></li>
<li role="presentation" class="Action"><a href="{% url 'movie:tag' %}?genre=Action">Action</a></li>
<li role="presentation" class="Comedy"><a href="{% url 'movie:tag' %}?genre=Comedy">Comedy</a></li>
<li role="presentation" class="Biography"><a href="{% url 'movie:tag' %}?genre=Biography">Biography</a></li>
<li role="presentation" class="Musical"><a href="{% url 'movie:tag' %}?genre=Family">Family</a></li>
<li role="presentation" class="Horror"><a href="{% url 'movie:tag' %}?genre=Horror">Horror</a></li>
<li role="presentation" class="Short"><a href="{% url 'movie:tag' %}?genre=Short">Short</a></li>
<li role="presentation" class="Documentary"><a
href="{% url 'movie:tag' %}?genre=Documentary">Documentary</a>
</li>
<li role="presentation" class="Film-Noir"><a href="{% url 'movie:tag' %}?genre=Film-Noir">Film-Noir</a></li>
<li role="presentation" class="Animation"><a href="{% url 'movie:tag' %}?genre=Animation">Animation</a></li>
<li role="presentation" class="Adventure"><a href="{% url 'movie:tag' %}?genre=Adventure">Adventure</a></li>
<li role="presentation" class="Mystery"><a href="{% url 'movie:tag' %}?genre=Mystery">Mystery</a></li>
<li role="presentation" class="News"><a href="{% url 'movie:tag' %}?genre=News">News</a></li>
<li role="presentation" class="Sport"><a href="{% url 'movie:tag' %}?genre=Sport">Sport</a></li>
<li role="presentation" class="History"><a href="{% url 'movie:tag' %}?genre=History">History</a></li>
<li role="presentation" class="Thriller"><a href="{% url 'movie:tag' %}?genre=Thriller">Thriller</a></li>
<li role="presentation" class="Western"><a href="{% url 'movie:tag' %}?genre=Western">Western</a></li>
</ul>
{% if genre %}
<div class="alert alert-info" role="alert">{{ genre }} 类型的电影:</div>
{% endif %}
</div>
<!--展示电影图片用-->
<div class="container">
{% for movie in movies %}
<a href="{% url 'movie:detail' movie.pk %}" class="item_">
<div class="poster_div">
<img src="/static/movie/poster/{{ movie.imdb_id }}.jpg" alt="">
<p>{{ movie.name }}
<strong style="color:#e09015">{{ movie.get_score }}</strong>
</p>
</div>
</a>
{% endfor %}
</div>
<nav style="text-align: center;">
<ul class="pagination">
{#previous page#}
{% if page_obj.has_previous %}
<li><a href="{% url 'movie:tag' %}?genre={{ genre }}&p={{ page_obj.previous_page_number }}">上一页</a></li>
{% else %}
<li class="disabled"><a href="javascript:void(0);">上一页</a></li>
{% endif %}
{% if left_has_more %}
<li><a href="{% url 'movie:tag' %}?genre={{ genre }}&p=1">1</a></li>
<li><a href="javascript:void(0)">...</a></li>
{% endif %}
{# 左边的page#}
{% for left_page in left_pages %}
<li><a href="{% url 'movie:tag' %}?genre={{ genre }}&p={{ left_page }}">{{ left_page }}</a></li>
{% endfor %}
{# 当前的page#}
<li class="active"><a href="javascript:void(0);">{{ current_page }}</a></li>
{# 右边的page#}
{% for right_page in right_pages %}
<li><a href="{% url 'movie:tag' %}?genre={{ genre }}&p={{ right_page }}">{{ right_page }}</a></li>
{% endfor %}
{% if right_has_more %}
<li><a href="javascript:void(0)">...</a></li>
<li><a href="{% url 'movie:tag' %}?genre={{ genre }}&p={{ paginator.num_pages }}">{{ paginator.num_pages }}</a></li>
{% endif %}
{#next page#}
{% if page_obj.has_next %}
<li><a href="{% url 'movie:tag' %}?genre={{ genre }}&p={{ page_obj.next_page_number }}">下一页</a></li>
{% else %}
<li class="disabled"><a href="javascript:void(0);">上一页</a></li>
{% endif %}
</ul>
</nav>
{% endblock %}
Loading…
Cancel
Save