def youtube(request):
    is_login = None
    try:
        is_login = request.session['is_login']
    except:
        pass
    if (not is_login):
        return render(request, 'youtube.html', {})
    elif (request.session['user_level'] < 0):
        return render(request, 'youtube.html', {})
    youtubes = Youtube.objects.using('youtube_db').all().values('title', 'description', 'cover', 'uploadtime', 'channeltitle', 'video').order_by('-uploadtime')
    paginator = Paginator(youtubes, 10)
    res = []
    if (request.method == 'GET'):
        page = request.GET.get('page')
        if (page is None):
            res_page = 1
        else:
            res_page = int(page)
        try:
            res = paginator.page(page).object_list
            pages = paginator.page(page)
        except PageNotAnInteger:
            res = paginator.page(1).object_list
            pages = paginator.page(1)
            res_page = 1
        except InvalidPage:
            return HttpResponse('找不到页面的内容')
        except EmptyPage:
            res = paginator.page(paginator.num_pages).object_list
            pages = paginator.page(paginator.num_pages)
    return render(request, 'youtube.html', {'data': res, 'pages': pages, 'current_page': res_page})
def youtube(request):
    is_login = None
    try:
        is_login = request.session['is_login']
    except:
        pass
    if (not is_login):
        return render(request, 'youtube.html', {})
    elif (request.session['user_level'] < 0):
        return render(request, 'youtube.html', {})
    youtubes = Youtube.objects.using('youtube_db').all().values('title', 'description', 'cover', 'uploadtime', 'channeltitle', 'video').order_by('-uploadtime')
    paginator = Paginator(youtubes, 10)
    res = []
    if (request.method == 'GET'):
        page = request.GET.get('page')
        if (page is None):
            res_page = 1
        else:
            res_page = int(page)
        try:
            res = paginator.page(page).object_list
            pages = paginator.page(page)
        except PageNotAnInteger:
            res = paginator.page(1).object_list
            pages = paginator.page(1)
            res_page = 1
        except InvalidPage:
            return HttpResponse('找不到页面的内容')
        except EmptyPage:
            res = paginator.page(paginator.num_pages).object_list
            pages = paginator.page(paginator.num_pages)
    return render(request, 'youtube.html', {'data': res, 'pages': pages, 'current_page': res_page})