django搭建一个AI博客进行YouTube视频自动生成文字博客

文章目录

  • 一、生成Django框架
  • 二、项目代码(前端)
    • 1、编写前端代码(正文界面)
      • 1.1、生产html框架
      • 1.2、添加live preview扩展
      • 1.3、更改title元素中文本
      • 1.4、添加CDN(CSS)样式链接
      • 1.5、nav标签
      • 1.6、在body标签中添加类
      • 1.7、nav下创建div标签
      • 1.8、当前界面预览
      • 1.9、在div标签后添加footer
      • 1.10、完整代码
    • 2、编写前端代码(登录注册界面)
      • 2.1、创建html框架并添加cdn样式表
      • 2.2、创建密码登录框(完整代码)
    • 3、编写前端代码(注册页面)
      • 3.1、完整代码
    • 4、编写前端代码(文章保存记录)
      • 4.1、完整代码
    • 5、编写前端代码(文章页面)
      • 5.1、完整代码
  • 三、Django代码(后端)
    • 1、添加app功能
    • 2、blog_generato添加index视图(views.py)
    • 3、添加数据库
    • 4、创建管理员用户
      • 4.1、后台中文化
      • 4.2、在blog_generato下的urls.py中添加url
      • 4.3、将注册登录html页面添加到views中
    • 5、获取ai转换
    • 6、获取openai秘钥
  • 四、修改后的完整代码(前后端)
    • 1、 ai_blog_app--> settings.py
    • 2、ai_blog_app--> urls.py
    • 3、ai_blog_app --> _init_.py
    • 4、blog_generato --> admin.py
    • 5、blog_generato --> models.py
    • blog_generato --> urls.py
    • 7、 blog_generato --> viwes.py
    • 8、templates --> all-logs.html(修改后)
    • 9、templates -->blog-details.html(修改后)
    • 10、templates -->index.html(修改后)
    • 11、templates -->login.html(修改后)
    • 12、templates -->signup.html(修改后)


一、生成Django框架

我这里使用的是PyCharm 2021.3.3

创建流程:

  • 打开PyCharm
  • 点击左上角File
  • 选择New Project
  • 选择Django
  • 最后点击Create
  • 然后在Django项目中添加一个文件夹,以便用来保存html文件
    在这里插入图片描述

二、项目代码(前端)

1、编写前端代码(正文界面)

1.1、生产html框架

使用Visual Studio Code打开你刚刚在django项目创建的用来编写html文件的文件夹

首先创建一个index.html文件
在这里插入图片描述
英文感叹号加回车键生成html框架
在这里插入图片描述

1.2、添加live preview扩展

Live Preview 扩展的作用是在VSCode内部实现边写边预览的效果。

这个扩展主要用于HTML文件,它允许开发者在编写代码的同时实时查看代码渲染的效果,而不需要离开编辑器或打开浏览器。具体来说,Live Preview 扩展提供了以下几个便利的功能:

实时预览:当你在编辑HTML文件时,任何对代码的更改都会立即反映在预览窗口中,这样你可以即时看到改动效果,提高开发效率。

高度集成:作为微软官方插件,Live Preview与VSCode的集成程度非常高,使用起来非常流畅和方便。

简化操作:相比于其他如LiveServer等插件,Live Preview无需额外的保存和重启服务步骤,减少了繁琐的操作流程。

易于安装:你可以通过VSCode的扩展商店直接搜索并安装Live Preview,安装过程简单快捷。

自定义布局:你可以根据自己的需要调整预览窗口的位置,选择向上/下/左/右拆分,以适应不同的工作流程和屏幕布局。

在这里插入图片描述
直接安装即可

右键点击index.html文件,然后选择显示预览
在这里插入图片描述

1.3、更改title元素中文本

更改第六行的title元素

<title>AI 博客</title>

然后ctrl + s保存

1.4、添加CDN(CSS)样式链接

在第七行添加css的链接

<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">

1.5、nav标签

从第十一行开始为nav标签


    <nav >
        
    </nav>

在第一个nav标签中添加一个类


    <nav class="bg-blue-600 p-4 text-white flex justify-between">

    </nav>

在nav标签中添加div标签

<div>

            <h1 class="text-3xl font-bold">AI 博客生成器</h1>

        </div>
        <div>
            <a href="#" class="text-white hover:underline">注销</a>

        </div>

1.6、在body标签中添加类

<body class="flex flex-col min-h-scrren bg-gray-100 font-sans antialised">

1.7、nav下创建div标签

创建h2标签之前先要创建三对div标签,三十八行到四十五行

   <div>
        <div>
            <div>
                <h2>欢迎来到AI博客生成器</h2>
            </div>
        </div>
    </div>

在最后一对div标签中创建h2和p标签

   <div>
        <div>

            <div class="text-center">

                <h2 class="text-2xl font-semibold mb-4">欢迎来到AI博客生成器</h2>

                <p class="text-gray-700">

                    使用人工智能从YouTube视频中生成高质量的博客文章。
                    只需输入链接到下面的YouTube视频,让人工智能为你创建内容!
                </p>
            </div>
        </div>

为前面两对div添加元素

   <div class="flex-grow container mx-auto mt-10 px-4 sm:px-0">


        <div class="max-w-3xl mx-auto bg-white p-6 rounded-lg">



            <div class="text-center">


                <h2 class="text-2xl font-semibold mb-4">欢迎来到AI博客生成器</h2>


                <p class="text-gray-700">

                    
                    使用人工智能从YouTube视频中生成高质量的博客文章。
                    只需输入链接到下面的YouTube视频,让人工智能为你创建内容!
                </p>
            </div>
        </div>

1.8、当前界面预览

在这里插入图片描述
在第二对div标签中添加内容

    <div class="flex-grow container mx-auto mt-10 px-4 sm:px-0">
        <div class="max-w-3xl mx-auto bg-white p-6 rounded-lg shadow-md transition-transform transform hover:scale-105 flex flex-col">
            <div class="text-center">
                <h2 class="text-2xl font-semibold mb-4">欢迎来到AI博客生成器</h2>
                <p class="text-gray-700">
                    使用人工智能从YouTube视频中生成高质量的博客文章。
                    只需输入链接到下面的YouTube视频,让人工智能为你创建内容!
                </p>
            </div>

            <br>

            <div>
                <h2 class="text-xl mb-4 font-semibold">请输入YouTube视频链接</h2>
                <div class="flex space-x-4">
                    <input id="youtubeLink" type="url" placeholder="请输入YouTube链接..." class="flex-grow p-2 border border-blue-400 rounded-l-md ">
                    <button id="generateBlogButton" class="bg-blue-600 text-blue px-4 py-2 rounded-r-md hover:gb-blue-700 transition-colors">提交</button>
                </div>
            </div>
        </div>

    </div>

添加section标签

    <div class="flex-grow container mx-auto mt-10 px-4 sm:px-0">
        <div class="max-w-3xl mx-auto bg-white p-6 rounded-lg shadow-md transition-transform transform hover:scale-105 flex flex-col">
            <div class="text-center">
                <h2 class="text-2xl font-semibold mb-4">欢迎来到AI博客生成器</h2>
                <p class="text-gray-700">
                    使用人工智能从YouTube视频中生成高质量的博客文章。
                    只需输入链接到下面的YouTube视频,让人工智能为你创建内容!
                </p>
            </div>

            <br>

            <div>
                <h2 class="text-xl mb-4 font-semibold">请输入YouTube视频链接</h2>
                <div class="flex space-x-4">
                    <input id="youtubeLink" type="url" placeholder="请输入YouTube链接..." class="flex-grow p-2 border border-blue-400 rounded-l-md ">
                    <button id="generateBlogButton" class="bg-blue-600 text-blue px-4 py-2 rounded-r-md hover:gb-blue-700 transition-colors">提交</button>
                </div>
            </div>

            <section class="mt-10 flex-grow">
                <h2 class="text-xl mb-4 font-semibold">生产博客文章</h2>
                <div id="blogContent" class="mt-2 text-gray-700 space-y-4">

                </div>
            </section>
        </div>

    </div>

1.9、在div标签后添加footer

    <footer class="text-center p-4 text-blacl mt-6">
        作者YouTube<a href="https://www.youtube.com/codewithtomi">链接</a>
    </footer>

1.10、完整代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI 博客</title>
    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
    <style>
        @keyframes rotate{
            from{
                transform: rotate(0deg);
            }
            to{
                transform: rotate(360deg);
            }
        }

        @-webkit-keyframes rotate{
            from{
                -webkit-transform: rotate(0deg);
            }
            to{
                -webkit-transform: rotate(360deg);
            }
        }

        .load{
            width: 100px;
            height: 100px;
            margin: 110px auto 0;
            border: solid 10px #8822aa;
            border-radius: 50%;
            border-right-color: transparent;
            border-bottom-color: transparent ;
             -webkit-transform: all 0.5s ease-in;
            -webkit-animation-name: rotate;
            -webkit-animation-duration: 1.0s;
            -webkit-animation-iteration-count: infinite;
            -webkit-animation-timing-function: linear;

                transition: all 0.5s ease-in;
                animation-name: rotate;
                animation-iteration-count: infinite;
                animation-timing-function: linear;
        }
    </style>

</head>
<body class="flex flex-col min-h-scrren bg-gray-100 font-sans antialised">
    <nav class="bg-blue-600 p-4 text-white flex justify-between">
        <div>
            <h1 class="text-3xl font-bold">AI 博客生成器</h1>
        </div>
        <div>
            <a href="#" class="text-white hover:underline">注销</a>
        </div>
    </nav>    
    <br>
    <br>
    <div class="flex-grow container mx-auto mt-10 px-4 sm:px-0">
        <div class="max-w-3xl mx-auto bg-white p-6 rounded-lg shadow-md transition-transform transform hover:scale-105 flex flex-col">
            <div class="text-center">
                <h2 class="text-2xl font-semibold mb-4">欢迎来到AI博客生成器</h2>
                <p class="text-gray-700">
                    使用人工智能从YouTube视频中生成高质量的博客文章。
                    只需输入链接到下面的YouTube视频,让人工智能为你创建内容!
                </p>
            </div>

            <br>

            <div>
                <h2 class="text-xl mb-4 font-semibold">请输入YouTube视频链接</h2>
                <div class="flex space-x-4">
                    <input id="youtubeLink" type="url" placeholder="请输入YouTube链接..." class="flex-grow p-2 border border-blue-400 rounded-l-md ">
                    <button id="generateBlogButton" class="bg-blue-600 text-blue px-4 py-2 rounded-r-md hover:gb-blue-700 transition-colors">提交</button>
                </div>
            </div>
            <div style="display: none;" id="loading-circle" class="load"></div>

            <section class="mt-10 flex-grow">
                <h2 class="text-xl mb-4 font-semibold">生产博客文章</h2>
                <div id="blogContent" class="mt-2 text-gray-700 space-y-4">

                </div>
            </section>
        </div>

    </div>
    
    <footer class="text-center p-4 text-blacl mt-6">
        作者YouTube<a href="https://www.youtube.com/codewithtomi">链接</a>
    </footer>
    <script>

    </script>
</body>
</html>

在这里插入图片描述

2、编写前端代码(登录注册界面)

2.1、创建html框架并添加cdn样式表

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI博客-登录</title>
    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
</head>
<body>

</body>
</html>

2.2、创建密码登录框(完整代码)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI博客-登录</title>
    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
</head>
<body class="bg-gray-100 font-sans antialiased">
    <nav class="bg-blue-600 p-4 text-white flex justify-between">
        <div>
            <h1 class="text-3xl font-bold">AI 博客生成器</h1>
        </div>
        <div>
            <a href="#" class="text-white hover:underline">登录</a>
            <a href="#" class="text-white hover:underline">注销</a>
        </div>
    </nav>

    <div class="flex items-center justify-center h-screen">
        <div class="bg-white p-8 shadow-md rounded-lg max-w-md w-full">
            <form class="space-y-4">
                <h2 class="text-xl font-semibold">登录</h2>
                <div>
                    <label for="username" class="block mb-1 font-medium">用户名</label>
                    <input type="text" id="username" name="username" placeholder="请输入您的用户名" class="w-full p-2 border rounded">
                </div>
                <div>
                    <label for="password" class="block mb-1 font-medium">密码</label>
                    <input type="password" id="password" name="password" placeholder="请输入您的密码" class="w-full p-2 border rounded">
                </div>
                <button type="submit" class="w-full bg-blue-600 text-white p-2 rounded hover:bg-blue-700">登录</button>
            </form>
        </div>
    </div>

</body>
</html>

在这里插入图片描述

3、编写前端代码(注册页面)

3.1、完整代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI博客-注册</title>
    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
</head>
<body class="bg-gray-100 font-sans antialiased">
    <nav class="bg-blue-600 p-4 text-white flex justify-between">
        <div>
            <h1 class="text-3xl font-bold">AI 博客生成器</h1>
        </div>
        <div>
            <a href="#" class="text-white hover:underline">登录</a>
            <a href="#" class="text-white hover:underline">注册</a>
        </div>
    </nav>
    <br>

    <div class="flex items-center justify-center h-screen">
        <div class="bg-white p-8 shadow-md rounded-lg max-w-md w-full">
            <form class="space-y-4">
                <h2 class="text-xl font-semibold">注册</h2>
                <div>
                    <label for="username" class="block mb-1 font-medium">用户名</label>
                    <input type="text" id="username" name="username" placeholder="请输入您的用户名" class="w-full p-2 border rounded">
                </div>
                <div>
                    <label for="email" class="block mb-1 font-medium">邮箱地址</label>
                    <input type="email" id="email" name="email" placeholder="请输入您的邮箱地址" class="w-full p-2 border rounded">
                </div>
                <div>
                    <label for="password" class="block mb-1 font-medium">密码</label>
                    <input type="password" id="password" name="password" placeholder="请输入您的密码" class="w-full p-2 border rounded">
                </div>
                <div>
                    <label for="repeatPassword" class="block mb-1 font-medium">密码确认</label>
                    <input type="password" id="repeatPassword" name="repeatPassword" placeholder="请再次输入您的密码" class="w-full p-2 border rounded">
                </div>
                <button type="submit" class="w-full bg-blue-600 text-white p-2 rounded hover:bg-blue-700">注册</button>
            </form>
        </div>
    </div>

</body>
</html>

在这里插入图片描述

4、编写前端代码(文章保存记录)

4.1、完整代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI博客-历史记录</title>
    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
</head>
<body class="bg-gray-100 font-sans antialiased">
    <nav class="bg-blue-600 p-4 text-white flex justify-between">
        <div>
            <h1 class="text-3xl font-bold">AI 博客生成器</h1>
        </div>
        <div>
            <a href="#" class="text-white hover:underline">登录</a>
            <a href="#" class="text-white hover:underline">注册</a>
        </div>
    </nav>
    <br>
    <br>
    <div class="container mx-auto mt-10 px-4 sm:px-0">
        <div class="max-w-3xl mx-auto bg-white p-6 rounded-lg shadow-md">
            <section>
                <h2 class="text-xl mb-4 font-semibold">AI博客-历史记录</h2>
                <div class="space-y-4">
                    <div class="border border-gray-300 p-4 rounded-lg">
                        <h3 class="text-lg font-semibold">博客文章标题1</h3>
                        <p>这是博客文章的内容,非常感谢</p>
                    </div>
                    <div class="border border-gray-300 p-4 rounded-lg">
                        <h3 class="text-lg font-semibold">博客文章标题1</h3>
                        <p>这是博客文章的内容,非常感谢</p>
                    </div>
                </div>
            </section>
        </div>
    </div>

    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <footer class="text-center p-4 text-black mt-6">
        <a href="https://www.youtube.com/codewithtomi">作者YouTube链接</a>
    </footer>
</body>
</html>

在这里插入图片描述

5、编写前端代码(文章页面)

5.1、完整代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客文章</title>
    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
</head>
<body class="bg-gray-100 font-sans antialiased">
    <nav class="bg-blue-600 p-4 text-white flex justify-between">
        <div>
            <h1 class="text-3xl font-bold">AI 博客生成器</h1>
        </div>
        <div>
            <a href="#" class="text-white hover:underline">登录</a>
            <a href="#" class="text-white hover:underline">注册</a>
        </div>
    </nav>
    <div class="container mx-auto mt-10 px-4 sm:px-0">
        <div class="max-w-3xl mx-auto bg-white p-6 rounded-lg shadow-md">
            <section>
                <h2 class="text-xl mb-4 font-semibold">博客文章详情</h2>
                <div class="border border-gray-300 p-4 rounded-lg">
                    <h3 class="text-lg font-semibold">博客文章标题</h3>
                    <p class="text-gray-700">博客文章内容</p>
                    <hr class="my-4 border-gray-300">
                    <h4 class="text-lg font-semibold">YouTube标题</h4>
                    <p class="text-gray-700">YouTube视频标签</p>
                    <h4 class="text-lg font-semibold mt-4">YouTube链接</h4>
                    <a href="#" class="text-blue-600 hover:underline">https://www.youtube.com</a>
                </div>
            </section>
        </div>
    </div>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <footer class="text-center p-4 text-black mt-6">
        <a href="https://www.youtube.com/codewithtomi">作者YouTube链接</a>
    </footer>
    
</body>
</html>

三、Django代码(后端)

1、添加app功能

ai_blog_app是生成django模版时随着django生成的
在这里插入图片描述

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'blog_generato'
]

然后将ai_blog_app中的urls.py复制到blog_generato中
在这里插入图片描述
在blog_generato下的urls.py中添加url

from  . import views
from django.urls import path

urlpatterns = [
    path('', views.index,name="index"),
]

2、blog_generato添加index视图(views.py)

首先在ai_blog_app的urls.py文件中添加url路径

from django.contrib import admin
from django.urls import path,include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('',include('blog_generato.urls'))
]

创建一个templates文件夹用来存放html前端代码,然后在ai_blog_app的settings.py问价中添加BASE_DIR , ‘templates’

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR , 'templates']
        ,
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

3、添加数据库

首先连接mysql数据库
在这里插入图片描述

在这里插入图片描述
根据自己使用的数据库来选择

注意:记得pip instal pymysql来安装mysql,然后在ai_blog_app下的_init_.py中添加代码,且已经创建好了django中需要使用的mysql环境

import pymysql

pymysql.install_as_MySQLdb()

然后更改ai_blog_app下settings.py中的mysql配置

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'ai_blog_app',
        'USER': 'root',
        'PASSWORD': 'yuan3128..',
        'HOST': 'localhost',
        'PORT': '3306',
    }

最后进行数据库迁移

PS E:\ai_blog_app> python manage.py makemigrations
PS E:\ai_blog_app> python manage.py migrate

4、创建管理员用户

PS E:\ai_blog_app> python manage.py createsuperuser
Username (leave blank to use 'yuanl'): (用户名)
Email address: (邮箱)
Password: (密码)
Password (again):(再次输入密码)
Superuser created successfully.

然后运行django项目,在浏览器中输入http://127.0.0.1:8000/admin进入后台管理页面
在这里插入图片描述

4.1、后台中文化

在seetings.py文件中将配置项LANGUAGE_CODE的值设置为“zh-Hans” ,TIME_ZONE的值设置为"Asia/Shanghai"

在seetings.py文件中配置项MIDDLEWARE(中间件)中添加本地化中间件
“django.middleware.locale.LocaleMiddleware”

LANGUAGE_CODE = 'zh-Hans'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True

4.2、在blog_generato下的urls.py中添加url

urlpatterns = [
    path('', views.index,name="index"),
    path('login', views.login, name="login"),
    path('signup', views.signup, name="signup"),
    path('logout', views.logout, name="logout"),
]

4.3、将注册登录html页面添加到views中

from django.shortcuts import render

# Create your views here.
def index(request):
    return render(request,'index.html')

def user_login(request):
    return render(request,'login.html')

def user_signup(request):
    return render(request,'signup.html')

修改signup.html中的代码

 <div>
            <a href="login" class="text-white hover:underline">登录</a>
            <a href="signup" class="text-white hover:underline">注册</a>
        </div>

修改login.html中的代码

 <div>
            <a href="login" class="text-white hover:underline">登录</a>
            <a href="signup" class="text-white hover:underline">注册</a>
        </div>

5、获取ai转换

地址:https://www.assemblyai.com/

注意:assemblyai库和websockets版本在10.0到11.0之间(根据自己的版本进行安装)
在这里插入图片描述
修改ai_blog_app中settings.py文件,并创建一个media文件夹

"""
Django settings for ai_blog_app project.

Generated by 'django-admin startproject' using Django 5.0.

For more information on this file, see
https://docs.djangoproject.com/en/5.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.0/ref/settings/
"""
import os.path
from pathlib import Path
import os

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-am#drmftow4qax@!l4v%_jg%pcr5)!@ibi*%@g(%he%!-i88#8'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'blog_generato',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'ai_blog_app.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR , 'templates']
        ,
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'ai_blog_app.wsgi.application'


# Database
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases

# DATABASES = {
#     'default': {
#         'ENGINE': 'django.db.backends.sqlite3',
#         'NAME': BASE_DIR / 'db.sqlite3',
#     }
# }
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'ai_blog_app',
        'USER': 'root',
        'PASSWORD': 'yuan3128..',
        'HOST': '127.0.0.1',
        'PORT': '3306',
    }
}



# Password validation
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/5.0/topics/i18n/

LANGUAGE_CODE = 'zh-Hans'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.0/howto/static-files/

STATIC_URL = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR,'media')

LOGIN_URL = 'login'

6、获取openai秘钥

地址:https://platform.openai.com/

因为地区原因无法注册

所以转文字功能无法使用

四、修改后的完整代码(前后端)

在这里插入图片描述

1、 ai_blog_app–> settings.py

import os.path
from pathlib import Path
import os

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-am#drmftow4qax@!l4v%_jg%pcr5)!@ibi*%@g(%he%!-i88#8'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'blog_generato',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'ai_blog_app.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR , 'templates']
        ,
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'ai_blog_app.wsgi.application'


# Database
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases

# DATABASES = {
#     'default': {
#         'ENGINE': 'django.db.backends.sqlite3',
#         'NAME': BASE_DIR / 'db.sqlite3',
#     }
# }
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'ai_blog_app',
        'USER': 'root',
        'PASSWORD': 'yuan3128..',
        'HOST': '127.0.0.1',
        'PORT': '3306',
    }
}



# Password validation
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/5.0/topics/i18n/

LANGUAGE_CODE = 'zh-Hans'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.0/howto/static-files/

STATIC_URL = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR,'media')

LOGIN_URL = 'login'

2、ai_blog_app–> urls.py

from django.contrib import admin
from django.urls import path,include
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    path('admin/', admin.site.urls),
    path('',include('blog_generato.urls'))
]
urlpatterns =urlpatterns+static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)

3、ai_blog_app --> init.py

import pymysql

pymysql.install_as_MySQLdb()

4、blog_generato --> admin.py

from django.contrib import admin
from .models import BlogPost

# Register your models here.
admin.site.register(BlogPost)

5、blog_generato --> models.py

from django.db import models
from django.contrib.auth.models import User
# Create your models here.
class BlogPost(models.Model):
    user = models.ForeignKey(User,on_delete=models.CASCADE)
    youtube_title = models.CharField(max_length=3000)
    youtube_link = models.URLField()
    generated_content = models.TextField()
    created_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return  self.youtube_title

blog_generato --> urls.py

from . import views
from django.urls import path

urlpatterns = [
    path('', views.index, name="index"),
    path('login', views.user_login, name="login"),
    path('signup', views.user_signup, name="signup"),
    path('logout', views.user_logout, name="logout"),
    path('generate', views.generate_blog, name="generate"),
    path('blog-list', views.blog_list, name="blog-list"),
    path('blog-details/<int:pk>/', views.blog_details, name="blog-details"),
]

7、 blog_generato --> viwes.py

import json
import os.path
import os
from django.contrib.auth.models import User
from django.contrib.auth import authenticate,login,logout
from django.shortcuts import render,redirect
from django.contrib.auth.decorators import login_required
from django.views.decorators.csrf import csrf_exempt
from django.http import JsonResponse
from pytube import YouTube
from django.conf import settings
import assemblyai as aai
# (无法注册)import openai
from .models import BlogPost

# Create your views here.
@login_required
def index(request):
    return render(request,'index.html')

@csrf_exempt
def generate_blog(request):
    if request.method == 'POST':
        try:
            data = json.loads(request.body)
            yt_link = data['link']
            return JsonResponse({'content':yt_link})
        except(KeyError,json.JSONDecodeError):
            return JsonResponse({'error':'无效的链接'},status=304)
        title = yt_title(yt_link)
        transcription = get_transcription(yt_link)
        if not transcription:
            return JsonResponse({'error':'未能获得转录'},status=500)
        blog_content = generate_blog_from_transcription(transcription)
        if not blog_content:
            return JsonResponse({'error': '未能获得转录'}, status=500)
        new_blog_article = BlogPost.objects.create(
            user= request.user,
            youtube_title=title,
            youtube_link=yt_link,
            generated_content=blog_content,
        )
        new_blog_article.save()
        return JsonResponse({'content':blog_content})



    else:
        return JsonResponse({'error':'无效的请求'},status=404)

def yt_title(link):
    yt = YouTube(link)
    title = yt.title
    return title

def download_audio(link):
    yt = YouTube(link)
    video = yt.streams.filter(only_audio=True).first()
    out_file = video.download(output_path=settings.MEDIA_ROOT)
    base,ext = os.path.splitext(out_file)
    new_file = base + '.mp3'
    os.rename(out_file,new_file)
    return new_file

def get_transcription(link):
    audio_file = download_audio(link)
    aai.settings.api_key = '5184545617204a3f80ef1fffc0a1056c'
    transcriber = aai.Transcriber
    transcriber = transcriber.transcriber(audio_file)

    return transcriber.text

def generate_blog_from_transcription(transcription):
    openai.api_key =" "
    prompt = f"Base on the following transcript from a YouTuBe vido,write a comprehensive blog article,write it based on the transcript,but dont make it look like a youtube video,make it look like a proper blog article:\n\n{transcription}\n\nArticle:"
    response = openai.Completion.create(
        model = "text-davinci-003",
        prompt = prompt,
        max_tokens = 1000
    )

    generated_content = response.choices[0].text.strip()
    return generated_content


def blog_list(request):
    blog_articles = BlogPost.objects.filter(user=request.user)
    return render(request,"all-logs.html",{'blog_articles':blog_articles})

def blog_details(request,pk):
    blog_article_detail = BlogPost.objects.get(id=pk)
    if request.user == blog_article_detail.user:
        return  render(request,'blog-details.html',{'blog_article_detail':blog_article_detail})
    else:
        return redirect('/')

def user_login(request):
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']

        user = authenticate(request,username=username,password=password)
        if user is not None:
            login(request,user)
            return redirect('/')
        else:
            error_message='没有该用户或密码错误'
            return render(request,'login.html',{'error_message':error_message})
    return render(request,'login.html')

def user_signup(request):
    if request.method == 'POST':
        username = request.POST['username']
        email = request.POST['email']
        password = request.POST['password']
        repeatPassword = request.POST['repeatPassword']
        if password == repeatPassword:
            try:
                user = User.objects.create_user(username,email,password)
                user.save()
                login(request,user)
                return redirect('/')
            except:
                error_message='创建账号失败'
                return render(request, 'signup.html', {'errot_message': error_message})
        else:
            error_message = '密码输入错误'
            return  render(request,'signup.html', {'errot_message':error_message})

    return render(request,'signup.html')


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

8、templates --> all-logs.html(修改后)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI博客-历史记录</title>
    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
</head>
<body class="bg-gray-100 font-sans antialiased">
    <nav class="bg-blue-600 p-4 text-white flex justify-between">
        <div>
            <h1 class="text-3xl font-bold">AI 博客生成器</h1>
        </div>
        <div>
            <a href="#" class="text-white hover:underline mx-4">欢迎{{ user.username }}</a>
            <a herf="/blog-list" class="text-white hover:underline mx-4">保存文章</a>
            <a href="#" class="text-white hover:underline">注销</a>
        </div>
    </nav>
    <br>
    <br>
    <div class="container mx-auto mt-10 px-4 sm:px-0">
        <div class="max-w-3xl mx-auto bg-white p-6 rounded-lg shadow-md">
            <section>
                <h2 class="text-xl mb-4 font-semibold">AI博客-历史记录</h2>
                <div class="space-y-4">
                    {% for article in blog_articles reversed %}
                    <a href="blog-details/{{ article.id }}">
                        <div class="border border-gray-300 p-4 rounded-lg">
                            <h3 class="text-lg font-semibold">{{ article.youtube_title }}</h3>
                            <p>{{ article.generated_content | truncatechars:200 }}</p>
                        </div>
                    </a>
                    {% endfor %}
                </div>
            </section>
        </div>
    </div>

    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <footer class="text-center p-4 text-black mt-6">
        <a href="https://www.youtube.com/codewithtomi">作者YouTube链接</a>
    </footer>
</body>
</html>

9、templates -->blog-details.html(修改后)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客文章</title>
    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
</head>
<body class="bg-gray-100 font-sans antialiased">
    <nav class="bg-blue-600 p-4 text-white flex justify-between">
        <div>
            <h1 class="text-3xl font-bold">AI 博客生成器</h1>
        </div>
        <div>
            <a href="#" class="text-white hover:underline mx-4">欢迎{{ user.username }}</a>
            <a herf="/blog-list" class="text-white hover:underline mx-4">保存文章</a>
            <a href="#" class="text-white hover:underline">注销</a>
        </div>
    </nav>
    <div class="container mx-auto mt-10 px-4 sm:px-0">
        <div class="max-w-3xl mx-auto bg-white p-6 rounded-lg shadow-md">
            <section>
                <h2 class="text-xl mb-4 font-semibold">博客文章详情</h2>
                <div class="border border-gray-300 p-4 rounded-lg">
                    <h3 class="text-lg font-semibold">{{ blog_article_detail.youtube_title }}</h3>
                    <p class="text-gray-700">{{ blog_article_detail.generated_content }}</p>
                    <hr class="my-4 border-gray-300">
                    <h4 class="text-lg font-semibold">YouTube标题</h4>
                    <p class="text-gray-700">{{ blog_article_detail.youtube_title }}</p>
                    <h4 class="text-lg font-semibold mt-4">YouTube链接</h4>
                    <a href="{{ blog_article_detail.youtube_link }}" class="text-blue-600 hover:underline">{{ blog_article_detail.youtube_link }}</a>
                </div>
            </section>
        </div>
    </div>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <footer class="text-center p-4 text-black mt-6">
        <a href="https://www.youtube.com/codewithtomi">作者YouTube链接</a>
    </footer>
    
</body>
</html>

10、templates -->index.html(修改后)

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI 博客</title>
    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
    <style>
        @keyframes rotate {
            from {
                transform: rotate(0deg);
            }

            to {
                transform: rotate(360deg);
            }
        }

        @-webkit-keyframes rotate {
            from {
                -webkit-transform: rotate(0deg);
            }

            to {
                -webkit-transform: rotate(360deg);
            }
        }

        .load {
            width: 100px;
            height: 100px;
            margin: 110px auto 0;
            border: solid 10px #8822aa;
            border-radius: 50%;
            border-right-color: transparent;
            border-bottom-color: transparent;
            -webkit-transform: all 0.5s ease-in;
            -webkit-animation-name: rotate;
            -webkit-animation-duration: 1.0s;
            -webkit-animation-iteration-count: infinite;
            -webkit-animation-timing-function: linear;

            transition: all 0.5s ease-in;
            animation-name: rotate;
            animation-iteration-count: infinite;
            animation-timing-function: linear;
        }
    </style>

</head>

<body class="flex flex-col min-h-screen bg-gray-100 font-sans antialised">
    <nav class="bg-blue-600 p-4 text-white flex justify-between">
        <div>
            <h1 class="text-3xl font-bold">AI 博客生成器</h1>
        </div>
<div>
            <a href="#" class="text-white hover:underline mx-4">欢迎{{ user.username }}</a>
            <a herf="/blog-list" class="text-white hover:underline mx-4">保存文章</a>
            <a href="#" class="text-white hover:underline">注销</a>
        </div>
    </nav>
    <br>
    <br>
    <div class="flex-grow container mx-auto mt-10 px-4 sm:px-0">
        <div
            class="max-w-3xl mx-auto bg-white p-6 rounded-lg shadow-md transition-transform transform hover:scale-105 flex flex-col">
            <div class="text-center">
                <h2 class="text-2xl font-semibold mb-4">欢迎来到AI博客生成器</h2>
                <p class="text-gray-700">
                    使用人工智能从YouTube视频中生成高质量的博客文章。
                    只需输入链接到下面的YouTube视频,让人工智能为你创建内容!
                </p>
            </div>

            <br>

            <div>
                <h2 class="text-xl mb-4 font-semibold">请输入YouTube视频链接</h2>
                <div class="flex space-x-4">
                    <input id="youtubeLink" type="url" placeholder="请输入YouTube链接..."
                        class="flex-grow p-2 border border-blue-400 rounded-l-md ">
                    <button id="generateBlogButton"
                        class="bg-blue-600 text-blue px-4 py-2 rounded-r-md hover:bg-blue-700 transition-colors">提交</button>
                </div>
            </div>
            <div style="display: none;" id="loading-circle" class="load"></div>

            <section class="mt-10 flex-grow">
                <h2 class="text-xl mb-4 font-semibold">生产博客文章</h2>
                <div id="blogContent" class="mt-2 text-gray-700 space-y-4">

                </div>
            </section>
        </div>

    </div>

    <footer class="text-center p-4 text-black mt-6">
        <a href="https://www.youtube.com/codewithtomi">作者YouTube链接</a>
    </footer>
    <script>
        document.getElementById('generateBlogButton').addEventListener('click',async () => {
            const youtubeLink = document.getElementById('youtubeLink').value;
            const blogContent = document.getElementById('blogContent');

            if(youtubeLink){
                document.getElementById('loading-circle').style.display = 'block';
                loadingIndicator.classList.remove('hidden');
                blogContent.innerHTML = '';

                const endpointUrl = '/generate';

                try {
                    const response = await fetch(endpointUrl,{
                        method:'POST',
                        headers:{
                            'Content-Type':'application/json',
                        },
                        body:JSON.stringify({link:youtubeLink})
                    });

                    const data = await response.json();

                    blogContent.innerHTML = data.youtubeLink;


                } catch (error) {
                    console.error("Error occurred:",error);
                    alert("Something went wrong. Please try again later.");

                }
                document.getElementById('loading-circle').style.display = 'none';
            } else {
                alert("Please enter a YouTube link.");
            }
        });
    </script>
</body>

</html>

11、templates -->login.html(修改后)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI博客-登录</title>
    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
</head>
<body class="bg-gray-100 font-sans antialiased">
    <nav class="bg-blue-600 p-4 text-white flex justify-between">
        <div>
            <h1 class="text-3xl font-bold">AI 博客生成器</h1>
        </div>
        <div>
            <a href="login" class="text-white hover:underline">登录</a>
            <a href="signup" class="text-white hover:underline">注册</a>
        </div>
    </nav>

    <div class="flex items-center justify-center h-screen">
        <div class="bg-white p-8 shadow-md rounded-lg max-w-md w-full">
            <form class="space-y-4" action="" method="POST">
                 {% csrf_token %}

                {% if error_message %}
                    <div align="center" style="color: red;">
                        <h2>
                            {{ 登录失败 }}登录失败或密码错误
                        </h2>
                    </div>
                {% endif %}
                <h2 class="text-xl font-semibold">登录</h2>
                <div>
                    <label for="username" class="block mb-1 font-medium">用户名</label>
                    <input type="text" id="username" name="username" placeholder="请输入您的用户名" class="w-full p-2 border rounded">
                </div>
                <div>
                    <label for="password" class="block mb-1 font-medium">密码</label>
                    <input type="password" id="password" name="password" placeholder="请输入您的密码" class="w-full p-2 border rounded">
                </div>
                <button type="submit" class="w-full bg-blue-600 text-white p-2 rounded hover:bg-blue-700">登录</button>
            </form>
        </div>
    </div>

</body>
</html>

12、templates -->signup.html(修改后)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI博客-注册</title>
    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
</head>
<body class="bg-gray-100 font-sans antialiased">
    <nav class="bg-blue-600 p-4 text-white flex justify-between">
        <div>
            <h1 class="text-3xl font-bold">AI 博客生成器</h1>
        </div>
        <div>
            <a href="login" class="text-white hover:underline">登录</a>
            <a href="signup" class="text-white hover:underline">注册</a>
        </div>
    </nav>
    <br>

    <div class="flex items-center justify-center h-screen">
        <div class="bg-white p-8 shadow-md rounded-lg max-w-md w-full">
            <form class="space-y-4" action="" method="POST">
                {% csrf_token %}

                {% if error_message %}
                    <div align="center" style="color: red;">
                        <h2>
                            {{ 注册失败 }}注册失败
                        </h2>
                    </div>
                {% endif %}
                <h2 class="text-xl font-semibold">注册</h2>
                <div>
                    <label for="username" class="block mb-1 font-medium">用户名</label>
                    <input type="text" id="username" name="username" placeholder="请输入您的用户名" class="w-full p-2 border rounded">
                </div>
                <div>
                    <label for="email" class="block mb-1 font-medium">邮箱地址</label>
                    <input type="email" id="email" name="email" placeholder="请输入您的邮箱地址" class="w-full p-2 border rounded">
                </div>
                <div>
                    <label for="password" class="block mb-1 font-medium">密码</label>
                    <input type="password" id="password" name="password" placeholder="请输入您的密码" class="w-full p-2 border rounded">
                </div>
                <div>
                    <label for="repeatPassword" class="block mb-1 font-medium">密码确认</label>
                    <input type="password" id="repeatPassword" name="repeatPassword" placeholder="请再次输入您的密码" class="w-full p-2 border rounded">
                </div>
                <button type="submit" class="w-full bg-blue-600 text-white p-2 rounded hover:bg-blue-700">注册</button>
            </form>
        </div>
    </div>

</body>
</html>

本篇文章是从YouTube上学的,地址:www.youtube.com/@CodeWithTomi

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/590900.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

021、Python+fastapi,第一个Python项目走向第21步:ubuntu 24.04 docker 安装mysql8、redis(二)

系列文章目录 pythonvue3fastapiai 学习_浪淘沙jkp的博客-CSDN博客https://blog.csdn.net/jiangkp/category_12623996.html 前言 安装redis 我会以三种方式安装&#xff0c; 第一、直接最简单安装&#xff0c;适用于测试环境玩玩 第二、conf配置安装 第三、集群环境安装 一…

Flutter笔记:Widgets Easier组件库(9)使用弹窗

Flutter笔记 Widgets Easier组件库&#xff08;9&#xff09;&#xff1a;使用弹窗 - 文章信息 - Author: 李俊才 (jcLee95) Visit me at CSDN: https://jclee95.blog.csdn.netMy WebSite&#xff1a;http://thispage.tech/Email: 291148484163.com. Shenzhen ChinaAddress o…

Redis---------实现更改数据业务,包括缓存更新,缓存穿透雪崩击穿的处理

三种更新策略 内存淘汰是Redis内存的自动操作&#xff0c;当内存快满了就会触发内存淘汰。超时剔除则是在存储Redis时加上其有限期(expire)&#xff0c;有限期一过就会自动删除掉。而主动更新则是自己编写代码去保持更新&#xff0c;所以接下来研究主动更新策略。 主动更新策略…

CSS 鼠标经过放大元素 不影响其他元素

效果 .item:hover{transform: scale(1.1); /* 鼠标悬停时将元素放大 1.1 倍 */ }.item{transition: transform 0.3s ease; /* 添加过渡效果&#xff0c;使过渡更加平滑 */ }

Ubuntu启动后进入GRUB故障-Minimal BASH like line editing is supported.

目录 1.问题描述 2.解决方案 2.1 临时性办法 2.2 工具永久性修复 总结 1.问题描述 PC安装Ubuntu系统第二天重启后提示GUN GRUB version 2.04&#xff0c;之前是WindowsOS装Ubuntu后无法进入图形界面。具体原因据网友提供线索据说是由于在Windows上进行更新/重装/修改了引…

最短路径(朴素)+堆排序+模拟堆

文章目录 Dijkstra求最短路 I堆排序模拟堆 Dijkstra求最短路 I 给定一个 n 个点 m 条边的有向图&#xff0c;图中可能存在重边和自环&#xff0c;所有边权均为正值。 请你求出 1 号点到 n 号点的最短距离&#xff0c;如果无法从 1 号点走到 n 号点&#xff0c;则输出 −1。 输…

2.6Java全栈开发前端+后端(全栈工程师进阶之路)-前端框架VUE3-基础-Vue生命周期

在使用vue进行日常开发中&#xff0c;我们总有这样的需求&#xff0c;想在页面刚一加载出这个表格组件时&#xff0c;就发送请求去后台拉取 数据&#xff0c;亦或者想在组件加载前显示个loading图&#xff0c;当组件加载出来就让这个loading图消失等等这样或那样的需求。 要实…

机器学习之基于Jupyter多种混合模型的糖尿病预测

欢迎大家点赞、收藏、关注、评论啦 &#xff0c;由于篇幅有限&#xff0c;只展示了部分核心代码。 文章目录 一项目简介 二、功能三、系统四. 总结 一项目简介 一、项目背景 随着现代生活方式的改变&#xff0c;糖尿病的患病率在全球范围内呈现上升趋势。糖尿病是一种慢性代谢…

k8s笔记 | Ingress

安装Ingress 添加helm创库 Installation Guide - Ingress-Nginx Controller Ingress | Kubernetes 下载包 将 文件helm 放到 /usr/local/bin/ 并给到执行权限 # 添加可执行权限 chmod ux helm # 测试是否能运行 helm version# 结果 version.BuildInfo{Version:"v3.14…

Vue Vant 移动端如何禁止手机调起自带的输入键盘

前言 前不久在公司用Vue2开发了一个手机充值项目&#xff0c;键盘组件用的vant2的NumberKeyboard 数字键盘组件&#xff1b;上线后在IOS端只有一个vant数字键盘组件&#xff0c;但到了Android端&#xff0c;输入框一获取焦点不仅vant数字键盘弹出&#xff0c;连手机自带的键盘…

python基础算法题0502

数字反转 无论是字符串反转还是数字反转&#xff0c;其实都一样。 需求 代码 class Solution:def reverse(self, x: int) -> int:if 0 < x < 2 ** 31 - 1:m str(x)[::-1]if int(m)<2**31-1:return int(m)else:return 0if 0 > x > -2 ** 31:y -xn str(y…

【软件工程】详细设计

目录 前言详细设计算法设计工具——判定表 前言 软件工程生命周期分为八个阶段&#xff1a; 问题定义—>可行性研究—>需求分析 —>概要设计—>详细设计—>编码与单元测试 —>综合测试—>软件维护 这节我们讲的是软件开发流程中的一个阶段&#xff0c;需求…

零代码编程:用Kimichat从PDF文件中批量提取图片

一个PDF文件中&#xff0c;有很多图片&#xff0c;想批量提取出来&#xff0c;可以借助kimi智能助手。 在借助kimi智能助手中输入提示词&#xff1a; 你是一个Python编程专家&#xff0c;要完成一个网页爬取Python脚本的任务&#xff0c;具体步骤如下&#xff1a; 打开文件夹…

【LeetCode刷题】410. 分割数组的最大值

1. 题目链接2. 题目描述3. 解题方法4. 代码 1. 题目链接 410. 分割数组的最大值 2. 题目描述 3. 解题方法 题目中提到的是某个和的最大值是最小的&#xff0c;这种题目是可以用二分来解决的。 确定区间&#xff0c;根据题目的数据范围&#xff0c;可以确定区间就是[0, 1e9]…

【云原生】Docker 实践(五):搭建私有镜像 Harbor

【Docker 实践】系列共包含以下几篇文章&#xff1a; Docker 实践&#xff08;一&#xff09;&#xff1a;在 Docker 中部署第一个应用Docker 实践&#xff08;二&#xff09;&#xff1a;什么是 Docker 的镜像Docker 实践&#xff08;三&#xff09;&#xff1a;使用 Dockerf…

uniapp 应用闪退、崩溃异常日志捕获插件(可对接网络上报)插件 Ba-Crash

应用闪退、崩溃异常日志捕获插件&#xff08;可对接网络上报&#xff09; Ba-Crash 简介&#xff08;下载地址&#xff09; Ba-Crash 是一款uniapp应用闪退、崩溃异常日志捕获插件&#xff0c;支持对接网络上报、设置提示等等&#xff0c;方便对一些远程问题、原生问题进行分…

C# dateTimePicker控件存取数据库问题

存入数据库时&#xff0c;先设置&#xff0c; dateTimePicker1.Format DateTimePickerFormat.Custom; dateTimePicker1.CustomFormat "yyyy-MM-dd HH:mm:ss"; 然后&#xff0c;dateTimePicker1.Text 就和textBox1.Text一样方式存入数据库&#xff1b;…

CMake:静态库链接其他动态库或静态库(九)

1、项目结构 对于下面这样一个项目 把calc模块做成静态或者动态库把sort模块做成静态库然后再sort模块中的*.cpp调用calc模块生成的库即可&#xff08;这样就制作了一个静态库引用动态或者静态库&#xff09;test模块用于测试sort模块中的内容 . ├── calc │ ├── ad…

《Mask2Former》算法详解

文章地址&#xff1a;《Masked-attention Mask Transformer for Universal Image Segmentation》 代码地址&#xff1a;https://github.com/facebookresearch/Mask2Former 文章为发表在CVPR2022的一篇文章。从名字可以看出文章像提出一个可以统一处理各种分割任务&#xff08;…

参考文献的力量:正确引用,提升论文质量

引用你的资料来源可能看起来是写作过程中一个乏味的步骤。通常更容易将任务推迟到最后一刻&#xff0c;结果却发现自己在最后制定了一份写得不好的引文列表。使用这些有用的引用说明将您的研究提升到另一个水平&#xff0c;从而省去麻烦。 引用参考文献的建议 引用来源的方法有…