main
syk1209wwz0306 6 months ago
parent 8d4d7669f4
commit 71416f7c1b

@ -20,7 +20,7 @@ from django.urls import path, include
from .views import index, star
urlpatterns = [
#path('admin/', admin.site.urls), # 后台管理系统
path('', index), # 首页
path('movie/', include('movie.urls')), # 电影推荐系统子路由
]

@ -1,6 +0,0 @@
from django.apps import AppConfig
class MovieConfig(AppConfig):
name = 'movie'
verbose_name = "电影推荐系统"

@ -1,68 +0,0 @@
from django import forms
from movie.models import User, Movie_rating
# 注册用的表单
class RegisterForm(forms.ModelForm):
password_repeat = forms.CharField(max_length=256)
def get_errors(self):
errors = self.errors.get_json_data()
errors_lst = []
for messages in errors.values():
for message_dict in messages:
for key, message in message_dict.items():
if key == 'message':
errors_lst.append(message)
return errors_lst
# 普通验证之后的最后一层验证
# 验证密码
def clean(self):
cleaned_data = super(RegisterForm, self).clean()
pwd = cleaned_data.get('password')
password_repeat = cleaned_data.get('password_repeat')
if pwd != password_repeat:
raise forms.ValidationError(message='两次密码输入不一致!')
return cleaned_data
class Meta:
model = User
fields = ['name', 'password', 'email']
# 登录的表单
class LoginForm(forms.ModelForm):
name = forms.CharField(max_length=128)
remember = forms.IntegerField(required=False)
class Meta:
model = User
fields = ['password']
def get_errors(self):
errors = self.errors.get_json_data()
errors_lst = []
for messages in errors.values():
for message_dict in messages:
for key, message in message_dict.items():
if key == 'message':
errors_lst.append(message)
return errors_lst
# 表单验证通过后再验证分数是否为0
class CommentForm(forms.ModelForm):
def clean(self):
cleaned_data = super(CommentForm, self).clean()
score = cleaned_data.get('score')
if score == 0:
raise forms.ValidationError(message='评分不能为空!')
else:
return cleaned_data
class Meta:
# 电影评分,只记录评分和评论
model = Movie_rating
fields = ['score', 'comment']

@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

@ -8,13 +8,10 @@ app_name = 'movie'
urlpatterns = [
# 默认首页
path('', views.IndexView.as_view(), name='index'),
# 电影详情页面
path('detail/<int:pk>', views.MovieDetailView.as_view(), name='detail'),
# 搜索功能
path('search', views.SearchView.as_view(), name='search'),
]

@ -14,7 +14,7 @@ class IndexView(ListView):
# 返回前1000部电影
def get_queryset(self):
return Movie.objects.order_by(self.ordering).filter(imdb_id__lte=1000)
return Movie.objects.order_by(self.ordering).filter(imdb_id__lte=666)
# 获取上下文数据
def get_context_data(self, *, object_list=None, **kwargs):

@ -36,13 +36,13 @@
html,
body {
height: 100%;
background-color: #333;
background-color: #658ab5;
}
body {
color: #fff;
text-align: center;
text-shadow: 0 1px 3px rgba(0, 0, 0, 0.48);
text-shadow: 0 1px 3px rgb(3, 31, 67);
}
/* Extra markup and styles for table-esque vertical and horizontal centering */
@ -51,8 +51,8 @@
width: 100%;
height: 100%; /* For at least Firefox */
min-height: 100%;
-webkit-box-shadow: inset 0 0 100px rgba(0, 0, 0, .5);
box-shadow: inset 0 0 100px rgba(0, 0, 0, .5);
-webkit-box-shadow: inset 0 0 100px rgb(3, 31, 67);
box-shadow: inset 0 0 100px rgb(3, 31, 67);
}
.site-wrapper-inner {

@ -20,8 +20,6 @@
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>

@ -18,12 +18,11 @@
<div class="container">
<div class="jumbotron">
<h1>项目简介</h1>
<p>数据集本系统使用最新的movielens数据集版本ml-latest-small该数据集该数据集包含9742部电影、
610个用户、100837个评分。有 links.csv (电影的imdbid和tmdbid)、 movies.csv (电影详情)、 ratings.csv (电影评分数据集 )等数据。
<p>
</p>
<p>系统首页会展示部分电影,热门电影会展示评分最高的前100部电影你可以点击任意一部电影查看详情</p>
<p>你可以给电影评分(需登录),查看网站对你的推荐(基于用户的协同过滤算法)</p>
<p>使用分类或搜索功能可以帮助你找到电影</p>
<p>系统首页会展示部分电影,你可以点击任意一部电影查看详情</p>
<p</p>
<p>使用搜索功能可以帮助你找到电影</p>
</div>
</div>
<!--展示电影图片用-->

@ -31,7 +31,7 @@
<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>

Loading…
Cancel
Save