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 pathurlpatterns = [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,includeurlpatterns = [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 pymysqlpymysql.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 = TrueUSE_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 = TrueALLOWED_HOSTS = []# Application definitionINSTALLED_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-validatorsAUTH_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 = TrueUSE_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-fieldDEFAULT_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 = TrueALLOWED_HOSTS = []# Application definitionINSTALLED_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-validatorsAUTH_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 = TrueUSE_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-fieldDEFAULT_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 staticurlpatterns = [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 pymysqlpymysql.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 pathurlpatterns = [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.titlereturn titledef 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_filedef get_transcription(link):audio_file = download_audio(link)aai.settings.api_key = '5184545617204a3f80ef1fffc0a1056c'transcriber = aai.Transcribertranscriber = transcriber.transcriber(audio_file)return transcriber.textdef 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_contentdef 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"><divclass="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

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Python | Leetcode Python题解之第66题加一

题目&#xff1a; 题解&#xff1a; class Solution:def plusOne(self, digits: List[int]) -> List[int]:n len(digits)for i in range(n - 1, -1, -1):if digits[i] ! 9:digits[i] 1for j in range(i 1, n):digits[j] 0return digits# digits 中所有的元素均为 9retu…

手撸Mybatis(三)——收敛SQL操作到SqlSession

本专栏的源码&#xff1a;https://gitee.com/dhi-chen-xiaoyang/yang-mybatis。 引言 在上一章中&#xff0c;我们实现了读取mapper配置并构造相关的mapper代理对象&#xff0c;读取mapper.xml文件中的sql信息等操作&#xff0c;现在&#xff0c;在上一章的基础上&#xff0c…

深度学习:基于TensorFlow、Keras,使用长短期记忆神经网络模型(LSTM)对Microsoft股票进行预测分析

前言 系列专栏&#xff1a;机器学习&#xff1a;高级应用与实践【项目实战100】【2024】✨︎ 在本专栏中不仅包含一些适合初学者的最新机器学习项目&#xff0c;每个项目都处理一组不同的问题&#xff0c;包括监督和无监督学习、分类、回归和聚类&#xff0c;而且涉及创建深度学…

分享我的github仓库

这是一个由现代C编写的小型、学习性质的服务器框架&#xff0c;包含压缩&#xff0c;序列化&#xff0c;IO调度&#xff0c;Socket封装&#xff0c;文件配置&#xff0c;日志库等多个完整自研模块&#xff0c;欢迎到我的仓库阅读代码和安装体验&#xff0c;期待任何的建议和反馈…

Docker 加持的安卓手机:随身携带的知识库(一)

这篇文章聊聊&#xff0c;如何借助 Docker &#xff0c;尝试将一台五年前的手机&#xff0c;构建成一个随身携带的、本地化的知识库。 写在前面 本篇文章&#xff0c;我使用了一台去年从二手平台购入的五年前的手机&#xff0c;K20 Pro。 为了让它能够稳定持续的运行&#xf…

如何从Mac电脑恢复任何删除的视频

Microsoft Office是包括Mac用户在内的人们在世界各地创建文档时使用的最佳软件之一。该软件允许您创建任何类型的文件&#xff0c;如演示文稿、帐户文件和书面文件。您可以使用 MS Office 来完成。所有Microsoft文档都可以在Mac上使用。大多数情况下&#xff0c;您处理文档&…

手搓堆(C语言)

Heap.h #pragma once#include <stdio.h> #include <stdlib.h> #include <assert.h> #include <stdbool.h> #include <string.h> typedef int HPDataType; typedef struct Heap {HPDataType* a;int size;int capacity; }Heap;//初始化 void Heap…

软件工程习题答案2024最新版

习题一答案 一、选择题 软件的主要特性是(A B C)。 A) **无形 **B) 高成本 C) **包括程序和文档 ** D) 可独立构成计算机系统 软件工程三要素是(B)。 A) 技术、方法和工具 B) 方法、工具和过程 C) 方法、对象和类 D) 过程、模型、方法 包含风险分析的软件工程模型是(A)…

深度学习之基于Matlab BP神经网络烟叶成熟度分类

欢迎大家点赞、收藏、关注、评论啦 &#xff0c;由于篇幅有限&#xff0c;只展示了部分核心代码。 文章目录 一项目简介 二、功能三、系统四. 总结 一项目简介 一、项目背景 烟叶的成熟度是评估烟叶品质的重要指标之一&#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…

uniapp 监听APP切换前台、后台插件 Ba-Lifecycle

监听APP切换前台、后台 Ba-Lifecycle 简介&#xff08;下载地址&#xff09; Ba-Lifecycle 是一款uniapp监听APP切换前台、后台的插件&#xff0c;简单易用。 截图展示 也可关注博客&#xff0c;实时更新最新插件&#xff1a; uniapp 常用原生插件大全 使用方法 在 script…

华为机考入门python3--(19)牛客19- 简单错误记录

分类&#xff1a;字符串 知识点&#xff1a; 分割字符串 my_str.split(\\) 字符串只保留最后16位字符 my_str[-16:] 列表可以作为队列、栈 添加元素到第一个位置 my_list.insert(0, elem) 增加元素到最后一个位置 my_list.append(elem) 删除第一个 my_list.pop(0)…

SAP_SD模块-销售批次策略应用记录

一、销售批次查找策略的重要性 批次查找策略允许企业在销售过程中根据预定义的规则自动选择最适合的产品批次。这种策略的实施&#xff0c;对企业尤其是那些涉及到严格产品质量与安全标准的行业&#xff08;如食品、药品及化工产品&#xff09;具有以下几方面的重要意义&#x…

[方法] Unity 实现仿《原神》第三人称跟随相机 v1.0

参考网址&#xff1a;【Unity中文课堂】RPG战斗系统Plus 在Unity游戏引擎中&#xff0c;实现类似《原神》的第三人称跟随相机并非易事&#xff0c;但幸运的是&#xff0c;Unity为我们提供了强大的工具集&#xff0c;其中Cinemachine插件便是实现这一目标的重要工具。Cinemachi…

从键入网址到网页显示,期间发生了什么?

从键入网址到网页显示&#xff0c;期间发生了什么&#xff1f; 孤单小弟【HTTP】真实地址查询【DNS】指南帮手【协议栈】可靠传输【TCP】远程定位【IP】两点传输【MAC】出口【网卡】送别者【交换机】出境大门【路由器】互相扒皮【服务器与客户端】相关问答 不少小伙伴在面试过程…

《21天学通C++》(第十五章)标准模板库简介

本章简单介绍STL容器、迭代器和算法的基本概念&#xff0c;之后几章会分别详述 1.STL容器 STL容器是STL中用于存储集合数据的组件&#xff0c;它们可以被看作是模板类&#xff0c;允许开发者定义特定类型的容器发&#xff0c;这里按照C11标准分为四类&#xff1a;顺序容器、关…

Qt5 框架学习及应用 — 对象树

Qt 对象树 对象树概念Qt为什么使用对象树 &#xff1f;将对象挂到对象树上 对象树概念 对象树&#xff1a;对于树的概念&#xff0c;相信许多学过数据结构的同学应该都不会陌生。在学习数据结构的时候我们所接触的什么二叉树、多叉树、哈夫曼树、AVL树、再到红黑树、B/B树………

vue处理查询框清除后无法查询问题,举例为日期选择

例如 在对应的查询方法添加 //我这里获取的是date&#xff0c;如果是其他参数改为其他的即可 if (query.date && query.date.length > 2) {conditions.noedate query.date[0] || conditions.noedate;//获取开始时间conditions.twodate query.date[1] || conditi…

实验14 MVC

二、实验项目内容&#xff08;实验题目&#xff09; 编写代码&#xff0c;掌握MVC的用法。【参考课本 例1 】 三、源代码以及执行结果截图&#xff1a; example7_1.jsp&#xff1a; <% page contentType"text/html" %> <% page pageEncoding "ut…

PHP医院安全(不良)事件报告系统源码 vue2+element支持11大类不良事件上报、审核处理、分析改进

PHP医院安全&#xff08;不良&#xff09;事件报告系统源码 vue2element支持11大类不良事件上报、审核处理、分析改进 医院安全&#xff08;不良&#xff09;事件管理系统采用无责的、自愿的填报不良事件方式&#xff0c;有效地减轻医护人员的思想压力&#xff0c;实现以事件为…