当前位置:   article > 正文

毕业设计:基于python旅游推荐系统+协同过滤推荐算法+爬虫+多种推荐算法+Django框架(附源码+论文)✅_旅游管理与推荐系统python+django网页平台+协同过滤推荐算法【计算机毕设项目

旅游管理与推荐系统python+django网页平台+协同过滤推荐算法【计算机毕设项目

博主介绍:✌全网粉丝10W+,前互联网大厂软件研发、集结硕博英豪成立工作室。专注于计算机相关专业毕业设计项目实战6年之久,选择我们就是选择放心、选择安心毕业✌感兴趣的可以先收藏起来,点赞、关注不迷路✌

毕业设计:2023-2024年计算机毕业设计1000套(建议收藏)

毕业设计:2023-2024年最新最全计算机专业毕业设计选题汇总

1、项目介绍

技术栈:
Django框架、requests爬虫、基于用户协同过滤推荐算法、MySQL数据库、多种推荐算法

旅游数据爬取推荐系统是一个基于用户协同过滤推荐算法的系统,使用Django框架进行开发,通过requests库进行数据爬取,数据存储在MySQL数据库中。

系统的主要功能是根据用户的兴趣和偏好,推荐他们可能感兴趣的旅游目的地或景点。该系统可以根据用户的历史行为和其他用户的行为,计算出用户之间的相似度,并根据相似度给出推荐结果。

2、项目界面

(1)旅游景点列表

在这里插入图片描述

(2)旅游景点详情页信息

在这里插入图片描述

(3)旅游推荐系统首页
在这里插入图片描述

(4)旅游景点推荐和评论功能
在这里插入图片描述
(5)旅游景点收藏和评分功能
在这里插入图片描述

(6)后台数据管理
在这里插入图片描述

(7)数据爬取
在这里插入图片描述

3、项目说明

旅游数据爬取推荐系统是一个基于用户协同过滤推荐算法的系统,使用Django框架进行开发,通过requests库进行数据爬取,数据存储在MySQL数据库中。

系统的主要功能是根据用户的兴趣和偏好,推荐他们可能感兴趣的旅游目的地或景点。该系统可以根据用户的历史行为和其他用户的行为,计算出用户之间的相似度,并根据相似度给出推荐结果。

推荐算法采用了多种方法,包括基于用户协同过滤、基于物品协同过滤、基于内容的推荐等。这些算法可以根据不同的情况和需求进行调整和组合,以提供更准确和个性化的推荐结果。

用户可以通过系统的界面进行注册和登录,系统会记录用户的行为数据并进行分析。用户可以浏览推荐的旅游目的地或景点,并对它们进行评分和评论,系统会根据这些反馈不断优化推荐结果。

在数据爬取方面,系统使用requests库发送HTTP请求,获取目标网站的数据。通过解析网页的HTML结构,提取出需要的信息,并存储在MySQL数据库中。可以定期更新数据,保持系统的推荐结果的新鲜性和准确性。

总之,旅游数据爬取推荐系统利用Django框架、requests爬虫、基于用户协同过滤推荐算法、MySQL数据库等技术,实现了一个能够根据用户兴趣和偏好推荐旅游目的地或景点的系统。

4、核心代码


# coding:utf-8
from django.views.decorators.csrf import csrf_exempt
from django.shortcuts import render, redirect, HttpResponse
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.decorators import login_required
from django.db.models import Q
from .algorithm import addr, ItemCF, UserCF
from tour.recomand import UserCf
from .models import *
import random
import json



@login_required(login_url='/login')
def init(request):
    # 推荐处理,根据游客的评分进行推荐
    recProducts = []
    datas = {}
    for user in User.objects.all():
        score = Score.objects.filter(user_id=user.id)
        dict = {}
        for sco in score:
            dict[sco.view_id] = sco.rate
        datas[user.username] = dict
    print("datas是",datas)

    userCf = UserCf(data=datas)

    recommandList = userCf.recomand(request.user.username, 10)  # 推荐10条 推荐列表  request.session.get('username')
    print("最终推荐:",recommandList)
    gue=View.objects.none()
    for r in recommandList:
        tables = View.objects.none()
        s_tables = tables.none()
        print(r)

        pro =View.objects.get(id=r[0])
        #s_tables += tables.filter(id=r[0])
        #gue=gue + View.objects.filter(id=r[0])
        recProducts.append({'id': pro.id, 'name': pro.view_name})

    print('pro ',pro )
    #print('s_tables ', s_tables)
    print(recProducts)

    if request.method == 'GET':
        # 热门推荐 按评分排序

        hot = View.objects.order_by('view_rate')[::-1]

        # 随机推荐某一地区景点


        #rand = View.objects.order_by('?')[:10]
        #rand = View.objects.filter(city=u'北京').order_by('view_rate')[::-1]
        rand = View.objects.all()

        # 猜你喜欢
        guess = recProducts

        data = {
            'hot': hot,
            'rand': rand,
            'guess': guess
        }
        print('随机猜测rand:', rand)
        print('guess:' ,guess)

        return render(request, 'index.html', data)


@csrf_exempt
@login_required(login_url='/login')
def detail(request):
    if request.method == 'GET':
        view_id = request.GET.get('id', False)
        view = View.objects.filter(id=view_id).first()

        # 类似推荐
        sim = View.objects.filter(city=view.city)

        # 该景点的评论
        comments = Comment.objects.filter(view=view).order_by('comment_date')[::-1]

        # 评分统计
        score = Score.objects.filter(view=view)
        pn = len(score)
        rate = round(sum(int(s.rate) for s in score) * 1.0 / pn, 1) if pn else 0.0#一位数平均

        collection = Collection.objects.filter(view=view, user=request.user)

        data = {
            'view': view,
            'sim': sim,
            'pn': pn,
            'comments': comments,
            'rate': rate,
            'collection': collection
        }
        print('view:' ,view)
        print('sim:', sim)
        print('comments:', comments)
        print('rate:', rate)
        print('collection:', collection)
        return render(request, 'detail.html', data)

    elif request.method == 'POST':
        comment = request.POST.get('text', False)
        view_id = request.POST.get('id', False)
        score = request.POST.get('score', False)
        collection = request.POST.get('collection', False)

        view = View.objects.get(id=view_id)

        msg = {
            'msg': '发生未知错误',
            'type': 'danger'
        }
        if comment:
            Comment.objects.create(user=request.user, view=view, comment=comment)
            msg['msg'] = '评论提交成功,页面即将刷新!'
            msg['type'] = 'success'

            return HttpResponse(json.dumps(msg), content_type='application/json')

        if score:
            score = int(score)
            s = Score.objects.filter(user=request.user, view=view)
            if s:
                s[0].rate = score
                s[0].save()
            else:
                Score.objects.create(user=request.user, view=view, rate=score)
            msg['msg'] = '感谢您的评分!'
            msg['type'] = 'success'
            return HttpResponse(json.dumps(msg), content_type='application/json')

        if collection:
            if collection == 'collection-true':
                Collection.objects.create(user=request.user, view=view)
                msg['msg'] = '收藏成功!'

            elif collection == 'collection-false':
                Collection.objects.filter(user=request.user, view=view).delete()
                msg['msg'] = '已取消收藏!'

            msg['type'] = 'success'
            return HttpResponse(json.dumps(msg), content_type='application/json')

        return HttpResponse(json.dumps(msg), content_type='application/json')


@csrf_exempt
def sign_in(request):
    if request.method == 'POST':
        username = request.POST.get('username', False)
        pw = request.POST.get('pw', False)
        user = authenticate(username=username, password=pw)
        if user:
            login(request, user)
            return redirect('/')

    if request.method == 'GET':
        username = request.GET.get('username', False)
        pw = request.GET.get('pw', False)
        if not username or not pw:
            return render(request, 'login.html')
        user = authenticate(username=username, password=pw)
        msg = {
            'msg': '登录成功,页面正在跳转!',
            'type': 'success'
        }
        if not user:
            msg['msg'] = '账号或密码错误,请检查后重新登录!'
            msg['type'] = 'danger'
        return HttpResponse(json.dumps(msg), content_type='application/json')


@csrf_exempt
def register(request):
    if request.method == 'POST':
        username = request.POST.get('username', False)
        pw = request.POST.get('pw', False)
        email = request.POST.get('email', False)

        # 生成随机编号
        number = random.randint(1000000, 9999999)
        if not ExtUser.objects.filter(number=number):
            user = User.objects.create_user(username=username, password=pw, email=email)
            ExtUser.objects.create(user=user, number=number)
            user = authenticate(username=username, password=pw)
            login(request, user)
            return redirect('/')

    elif request.method == 'GET':
        username = request.GET.get('username', False)
        pw = request.GET.get('pw', False)
        rpw = request.GET.get('rpw', False)
        if not username or not pw:
            return render(request, 'register.html')
        msg = {
            'msg': '账号注册成功!',
            'type': 'success'
        }
        if not pw.isalnum():
            msg['msg'] = '密码只能由数字字母组成!'
            msg['type'] = 'danger'
        if pw != rpw:
            msg['msg'] = '两次输入的密码不一致!'
            msg['type'] = 'danger'
        if len(pw) < 6:
            msg['msg'] = '密码至少需要6个字符!'
            msg['type'] = 'danger'
        if User.objects.filter(username=username):
            msg['msg'] = '用户名已经存在!'
            msg['type'] = 'danger'

        return HttpResponse(json.dumps(msg), content_type='application/json')


def sign_out(request):
    logout(request)
    return redirect('/')


def search(request):
    if request.method == 'GET':
        word = request.GET.get('word', False)
        views = View.objects.filter(Q(province__contains=word) | Q(view_name__contains=word) | Q(city__contains=word))

        for v in views:
            score = Score.objects.filter(view=v)
            v.view_rate = sum(s.rate for s in score)*1.0/len(score) if score else 0

        return render(request, 'search.html', {'views': views})


@login_required(login_url='/login')
def collection(request):
    views = Collection.objects.filter(user=request.user)
    return render(request, 'collection.html', {'views': views})



@login_required(login_url='/login')
@csrf_exempt
def info(request):
    if request.method == 'GET':
        return render(request, 'info.html')
    elif request.method == 'POST':
        username = request.POST.get('username', False)
        password = request.POST.get('password', False)
        sex = request.POST.get('sex', False)
        age = request.POST.get('age', False)
        address = request.POST.get('address', False)

        user = request.user
        user.username = username
        if password:
            user.set_password(password)
        user.extuser.sex = sex
        user.extuser.age = age
        user.extuser.address = address
        user.extuser.save()
        user.save()

        return redirect('/login')




  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253
  • 254
  • 255
  • 256
  • 257
  • 258
  • 259
  • 260
  • 261
  • 262
  • 263
  • 264
  • 265
  • 266
  • 267
  • 268
  • 269
  • 270
  • 271
  • 272
  • 273

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/424035
推荐阅读
相关标签