【小沐学Python】Python实现Web服务器(Flask+Vue+node.js,web单页增删改查)

news2024/10/5 9:58:14

文章目录

  • 1、简介
    • 1.1 flask
    • 1.2 vue
  • 2、开发
    • 2.1 新建flask项目
    • 2.2 安装flask库
    • 2.3 新建flask的主脚本
    • 2.4 新建Vue项目
    • 2.5 安装vue项目依赖项
    • 2.6 新增组件Ping.vue
    • 2.7 Ping.vue增加HTTP请求
    • 2.8 美化vue前端页面
    • 2.9 新增组件Books.vue
    • 2.10 flask增加路由Books
    • 2.11 Books.vue增加HTTP请求
    • 2.12 flask修改路由Books
    • 2.13 Books.vue增加添加接口
    • 2.14 新增组件Alert.vue
    • 2.15 修改组件Alert.vue
    • 2.16 变量绑定Alert组件
    • 2.17 flask端Book对象添加唯一id
    • 2.18 Books.vue增加更新操作
  • 结语

1、简介

1.1 flask

Flask是一个简单但功能强大的Python微Web框架,非常适合构建RESTful API。像Sinatra(Ruby)和Express(Node)一样,它是最小和灵活的,所以你可以从小处着手,然后根据需要构建更复杂的应用程序。

安装如下:

pip install flask

在这里插入图片描述

1.2 vue

Vue 是一个用于构建用户界面的开源 JavaScript 框架。它采用了React和Angular的一些最佳实践。也就是说,与 React 和 Angular 相比,它更平易近人,因此初学者可以快速启动和运行。它也同样强大,因此它提供了创建现代前端应用程序所需的所有功能。

安装如下:

npm create vue@3.6.1

在这里插入图片描述

2、开发

2.1 新建flask项目

首先创建一个新的项目目录:

mkdir flask-vue-crud
cd flask-vue-crud

在这里插入图片描述

创建并激活虚拟环境:

python -m venv myvenv
.\myvenv\Scripts\activate

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

2.2 安装flask库

将 Flask 与 Flask-CORS 扩展一起安装:

pip install Flask  Flask-Cors

在这里插入图片描述

2.3 新建flask的主脚本

app.py:

# -*- coding:utf-8 -*-

from flask import Flask, jsonify, make_response
from flask_cors import CORS

class Config(object):
    DEBUG=True
    JSON_AS_ASCII=False

# instantiate the app
app = Flask(__name__)
# app.config.from_object(__name__)
app.config.from_object(Config)
# app.config["JSON_AS_ASCII"] = False
# app.config['DEBUG'] = True
# app.config['JSONIFY_MIMETYPE'] = "application/json;charset=utf-8"

# enable CORS
CORS(app, resources={r'/*': {'origins': '*'}})

@app.route('/', methods=['GET'])
def index():
    response = make_response(jsonify('爱看书的小沐!'))
    response.headers['Content-Type'] = 'application/json;charset=utf-8'
    return response
    # return jsonify('爱看书的小沐!')
    
# sanity check route
@app.route('/ping', methods=['GET'])
def ping_pong():
    return jsonify("xiaomu's pong!")

if __name__ == '__main__':
    app.run(port=5001)

运行上面这个脚本:

flask run --port=5001 --debug

在这里插入图片描述

在这里插入图片描述

2.4 新建Vue项目

使用强大的create-vue工具,它使用Vite来生成一个定制的项目样板。
在 “flask-vue-crud” 中,运行以下命令来初始化一个新的 Vue 项目:

npm create vue@3.6.1

在这里插入图片描述
快速浏览生成的项目结构。这可能看起来很多,但我们只会处理“src”文件夹中的文件和文件夹以及index.html文件。
在这里插入图片描述

main.js	:app 入口点,它加载并初始化 Vue 以及根组件
App.vue:根组件,这是呈现所有其他组件的起点
"components"	:UI 组件的存储位置
router/index.js	:定义 URL 并将其映射到组件的位置
"views":	绑定到路由器的 UI 组件的存储位置
"assets":静态资产(如图像和字体)的存储位置

查看 client/src/components/HelloWorld.vue 文件。这是一个单个文件组件,分为三个不同的部分:

模板:用于特定于组件的 HTML
脚本:组件逻辑通过JavaScript实现
样式:用于 CSS 样式

其中index.html 文件是我们 Vue 应用程序的起点:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <link rel="icon" href="/favicon.ico">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vite App</title>
  </head>
  <body>
    <div id="app"></div>
    <script type="module" src="/src/main.js"></script>
  </body>
</html>

2.5 安装vue项目依赖项

$ cd vue-project
$ npm install
$ npm run dev

在这里插入图片描述
浏览器访问如下:
在这里插入图片描述

2.6 新增组件Ping.vue

为了简化操作,请删除“vue-project/src/views”和“vue-project/src/components/icons”文件夹以及vue-project/src/components/TheWelcome.vue和vue-project/src/components/WelcomeItem.vue组件。然后,将一个名为 Ping.vue 的新组件添加到名为 Ping.vue 的“vue-project/src/components”文件夹中:

<template>
  <div>
    <p>{{ msg }}</p>
  </div>
</template>

<script>
export default {
  name: 'Ping',
  data() {
    return {
      msg: 'Hello!',
    };
  },
};
</script>

更新客户端/src/router/index.js将“/ping”映射到组件,如下所示:

import { createRouter, createWebHistory } from 'vue-router'
import Ping from '../components/Ping.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/ping',
      name: 'ping',
      component: Ping
    },
  ]
})

export default router

最后,在 vue-project/src/App.vue 中,删除导航以及样式:

<template>
  <RouterView />
</template>

<script setup>
import { RouterView } from 'vue-router'
</script>

在浏览器访问: http://localhost:5173/ping
在这里插入图片描述

2.7 Ping.vue增加HTTP请求

要将客户端 Vue 应用程序与后端 Flask 应用程序连接起来,我们可以使用 Axios 库发送 HTTP 请求。

npm install axios@1.3.6 --save

在 Ping.vue 中更新组件的部分,如下所示:

<template>
  <div>
    <p>{{ msg }}</p>
  </div>
</template>

<script>
import axios from 'axios';

export default {
  name: 'Ping',
  data() {
    return {
      msg: '',
    };
  },
  methods: {
    getMessage() {
      const path = 'http://localhost:5001/ping';
      axios.get(path)
        .then((res) => {
          this.msg = res.data;
        })
        .catch((error) => {

          console.error(error);
        });
    },
  },
  created() {
    this.getMessage();
  },
};
</script>

随着 Vue 应用程序在不同的终端窗口中运行,您现在应该在浏览器中看到。
在这里插入图片描述

2.8 美化vue前端页面

接下来,让我们将 Bootstrap(一个流行的 CSS 框架)添加到应用程序中,以便我们可以快速添加一些样式。

npm install bootstrap@5.2.3 --save

将引导程序样式导入客户端/src/main.js:

import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import 'bootstrap/dist/css/bootstrap.css' //add by tomcat

import './assets/main.css'

const app = createApp(App)
app.use(router)
app.mount('#app')

更新vue-project\src\components\Ping.vue的template部分:

<template>
  <div class="container">
    <button type="button" class="btn btn-primary">{{ msg }}</button>
  </div>
</template>

运行开发服务器:
在这里插入图片描述

2.9 新增组件Books.vue

<template>
  <div class="container">
    <div class="row">
      <div class="col-sm-10">
        <h1>Books</h1>
        <hr><br><br>
        <button type="button" class="btn btn-success btn-sm">Add Book</button>
        <br><br>
        <table class="table table-hover">
          <thead>
            <tr>
              <th scope="col">Title</th>
              <th scope="col">Author</th>
              <th scope="col">Read?</th>
              <th></th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td>foo</td>
              <td>bar</td>
              <td>foobar</td>
              <td>
                <div class="btn-group" role="group">
                  <button type="button" class="btn btn-warning btn-sm">Update</button>
                  <button type="button" class="btn btn-danger btn-sm">Delete</button>
                </div>
              </td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</template>

修改路由文件:vue-project\src\router\index.js

import { createRouter, createWebHistory } from 'vue-router'
import Books from '../components/Books.vue'
import Ping from '../components/Ping.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'Books',
      component: Books,
    },
    {
      path: '/ping',
      name: 'ping',
      component: Ping
    },
  ]
})

export default router

浏览器访问:http://localhost:5173
在这里插入图片描述

2.10 flask增加路由Books

app.py:

BOOKS = [
    {
        'title': 'On the Road',
        'author': 'Jack Kerouac',
        'read': True
    },
    {
        'title': 'Harry Potter and the Philosopher\'s Stone',
        'author': 'J. K. Rowling',
        'read': False
    },
    {
        'title': 'Green Eggs and Ham',
        'author': 'Dr. Seuss',
        'read': True
    }
]

@app.route('/books', methods=['GET'])
def all_books():
    return jsonify({
        'status': 'success',
        'books': BOOKS
    })

浏览器访问如下:
在这里插入图片描述

2.11 Books.vue增加HTTP请求

<template>
  <div class="container">
    <div class="row">
      <div class="col-sm-10">
        <h1>Books</h1>
        <hr><br><br>
        <button type="button" class="btn btn-success btn-sm">Add Book</button>
        <br><br>
        <table class="table table-hover">
          <thead>
            <tr>
              <th scope="col">Title</th>
              <th scope="col">Author</th>
              <th scope="col">Read?</th>
              <th></th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="(book, index) in books" :key="index">
              <td>{{ book.title }}</td>
              <td>{{ book.author }}</td>
              <td>
                <span v-if="book.read">Yes</span>
                <span v-else>No</span>
              </td>
              <td>
                <div class="btn-group" role="group">
                  <button type="button" class="btn btn-warning btn-sm">Update</button>
                  <button type="button" class="btn btn-danger btn-sm">Delete</button>
                </div>
              </td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</template>

<script>
import axios from 'axios';

export default {
  data() {
    return {
      books: [],
    };
  },
  methods: {
    getBooks() {
      const path = 'http://localhost:5001/books';
      axios.get(path)
        .then((res) => {
          this.books = res.data.books;
        })
        .catch((error) => {
          console.error(error);
        });
    },
  },
  created() {
    this.getBooks();
  },
};
</script>

浏览器访问如下:
在这里插入图片描述

2.12 flask修改路由Books

from flask import Flask, jsonify, request

@app.route('/books', methods=['GET', 'POST'])
def all_books():
    response_object = {'status': 'success'}
    if request.method == 'POST':
        post_data = request.get_json()
        BOOKS.append({
            'title': post_data.get('title'),
            'author': post_data.get('author'),
            'read': post_data.get('read')
        })
        response_object['message'] = 'Book added!'
    else:
        response_object['books'] = BOOKS
    return jsonify(response_object)

运行 Flask 服务器后,您可以在新的终端选项卡中测试 POST 路由:

curl -X POST http://localhost:5001/books -d  "{\"title\": \"1024\", \"author\": \"Xiao Mu\", \"read\": \"true\"}"  -H "Content-Type: application/json"

命令行输入curl指令如下:
在这里插入图片描述
flask的web服务端的信息输出如下:
在这里插入图片描述
vue前端页面的最下面增加了一行记录如下:
在这里插入图片描述

2.13 Books.vue增加添加接口

<template>
  <div class="container">
    <div class="row">
      <div class="col-sm-10">
        <h1>Books</h1>
        <hr><br><br>
        <button
          type="button"
          class="btn btn-success btn-sm"
          @click="toggleAddBookModal">
          Add Book
        </button>
        <br><br>
        <table class="table table-hover">
          <thead>
            <tr>
              <th scope="col">Title</th>
              <th scope="col">Author</th>
              <th scope="col">Read?</th>
              <th></th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="(book, index) in books" :key="index">
              <td>{{ book.title }}</td>
              <td>{{ book.author }}</td>
              <td>
                <span v-if="book.read">Yes</span>
                <span v-else>No</span>
              </td>
              <td>
                <div class="btn-group" role="group">
                  <button type="button" class="btn btn-warning btn-sm">Update</button>
                  <button type="button" class="btn btn-danger btn-sm">Delete</button>
                </div>
              </td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>

    <!-- add new book modal -->
    <div
      ref="addBookModal"
      class="modal fade"
      :class="{ show: activeAddBookModal, 'd-block': activeAddBookModal }"
      tabindex="-1"
      role="dialog">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title">Add a new book</h5>
            <button
              type="button"
              class="close"
              data-dismiss="modal"
              aria-label="Close"
              @click="toggleAddBookModal">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div class="modal-body">
            <form>
              <div class="mb-3">
                <label for="addBookTitle" class="form-label">Title:</label>
                <input
                  type="text"
                  class="form-control"
                  id="addBookTitle"
                  v-model="addBookForm.title"
                  placeholder="Enter title">
              </div>
              <div class="mb-3">
                <label for="addBookAuthor" class="form-label">Author:</label>
                <input
                  type="text"
                  class="form-control"
                  id="addBookAuthor"
                  v-model="addBookForm.author"
                  placeholder="Enter author">
              </div>
              <div class="mb-3 form-check">
                <input
                  type="checkbox"
                  class="form-check-input"
                  id="addBookRead"
                  v-model="addBookForm.read">
                <label class="form-check-label" for="addBookRead">Read?</label>
              </div>
              <div class="btn-group" role="group">
                <button
                  type="button"
                  class="btn btn-primary btn-sm"
                  @click="handleAddSubmit">
                  Submit
                </button>
                <button
                  type="button"
                  class="btn btn-danger btn-sm"
                  @click="handleAddReset">
                  Reset
                </button>
              </div>
            </form>
          </div>
        </div>
      </div>
    </div>
    <div v-if="activeAddBookModal" class="modal-backdrop fade show"></div>
  </div>
</template>

<script>
import axios from 'axios';

export default {
  data() {
    return {
      activeAddBookModal: false,
      addBookForm: {
        title: '',
        author: '',
        read: [],
      },
      books: [],
    };
  },
  methods: {
    addBook(payload) {
      const path = 'http://localhost:5001/books';
      axios.post(path, payload)
        .then(() => {
          this.getBooks();
        })
        .catch((error) => {

          console.log(error);
          this.getBooks();
        });
    },
    getBooks() {
      const path = 'http://localhost:5001/books';
      axios.get(path)
        .then((res) => {
          this.books = res.data.books;
        })
        .catch((error) => {

          console.error(error);
        });
    },
    handleAddReset() {
      this.initForm();
    },
    handleAddSubmit() {
      this.toggleAddBookModal();
      let read = false;
      if (this.addBookForm.read[0]) {
        read = true;
      }
      const payload = {
        title: this.addBookForm.title,
        author: this.addBookForm.author,
        read, // property shorthand
      };
      this.addBook(payload);
      this.initForm();
    },
    initForm() {
      this.addBookForm.title = '';
      this.addBookForm.author = '';
      this.addBookForm.read = [];
    },
    toggleAddBookModal() {
      const body = document.querySelector('body');
      this.activeAddBookModal = !this.activeAddBookModal;
      if (this.activeAddBookModal) {
        body.classList.add('modal-open');
      } else {
        body.classList.remove('modal-open');
      }
    },
  },
  created() {
    this.getBooks();
  },
};
</script>

在这里插入图片描述

2.14 新增组件Alert.vue

让我们添加一个组件,以便在添加新书籍后向最终用户显示消息。我们将为此创建一个新组件Alert.vue,因为您可能会在许多组件中使用该功能。
将一个名为 Alert.vue 的新文件添加到 “vue-project/src/components”:

<template>
  <p>It works!爱看书的小沐正在添加Alert</p>
</template>

然后,将其添加到Books.vue中:

<script>
import axios from 'axios';
import Alert from './Alert.vue';

export default {
  data() {
    return {
      activeAddBookModal: false,
      addBookForm: {
        title: '',
        author: '',
        read: [],
      },
      books: [],
    };
  },
  components: {
    alert: Alert,
  },

  ...

};
</script>

在Books.vue的template部分也添加Alert的使用:

<template>
  <div class="container">
    <div class="row">
      <div class="col-sm-10">
        <h1>Books</h1>
        <hr><br><br>
        <alert></alert>
        <button
          type="button"
          class="btn btn-success btn-sm"
          @click="toggleAddBookModal">
          Add Book
        </button>
        <br><br>

        ...

      </div>
    </div>

    ...

  </div>
</template>

前端预览如下:
在这里插入图片描述

2.15 修改组件Alert.vue

<template>
  <div>
    <div class="alert alert-success" role="alert">{{ message }}</div>
    <br/>
  </div>
</template>

<script>
export default {
  props: ['message'],
};
</script>

同时修改Books.vue的template部分中的alert代码:

<alert message="hi, 爱看书的小沐"></alert>

在这里插入图片描述

2.16 变量绑定Alert组件

Books.vue 中使用绑定表达式。修改Books.vue的template部分中的alert代码:

<alert :message="message"></alert>

修改Books.vue的script的data()函数:

data() {
  return {
    activeAddBookModal: false,
    addBookForm: {
      title: '',
      author: '',
      read: [],
    },
    books: [],
    message: '',
  };
},

修改Books.vue的script的addBook()函数:

addBook(payload) {
  const path = 'http://localhost:5001/books';
  axios.post(path, payload)
    .then(() => {
      this.getBooks();
      this.message = 'Book added!';
    })
    .catch((error) => {
      console.log(error);
      this.getBooks();
    });
},

仅在 true 时显示警报:v-ifshowMessage:

<alert :message=message v-if="showMessage"></alert>
data() {
  return {
    activeAddBookModal: false,
    addBookForm: {
      title: '',
      author: '',
      read: [],
    },
    books: [],
    message: '',
    showMessage: false,
  };
},
addBook(payload) {
  const path = 'http://localhost:5001/books';
  axios.post(path, payload)
    .then(() => {
      this.getBooks();
      this.message = 'Book added!';
      this.showMessage = true;
    })
    .catch((error) => {
      console.log(error);
      this.getBooks();
    });
},

在这里插入图片描述

2.17 flask端Book对象添加唯一id

import uuid

BOOKS = [
    {
        'id': uuid.uuid4().hex,
        'title': 'On the Road',
        'author': 'Jack Kerouac',
        'read': True
    },
]

@app.route('/books', methods=['GET', 'POST'])
def all_books():
    response_object = {'status': 'success'}
    if request.method == 'POST':
        post_data = request.get_json()
        BOOKS.append({
            'id': uuid.uuid4().hex,
            'title': post_data.get('title'),
            'author': post_data.get('author'),
            'read': post_data.get('read')
        })
        response_object['message'] = 'Book added!'
    else:
        response_object['books'] = BOOKS
    return jsonify(response_object)

@app.route('/books/<book_id>', methods=['PUT'])
def single_book(book_id):
    response_object = {'status': 'success'}
    if request.method == 'PUT':
        post_data = request.get_json()
        remove_book(book_id)
        BOOKS.append({
            'id': uuid.uuid4().hex,
            'title': post_data.get('title'),
            'author': post_data.get('author'),
            'read': post_data.get('read')
        })
        response_object['message'] = 'Book updated!'
    return jsonify(response_object)

def remove_book(book_id):
    for book in BOOKS:
        if book['id'] == book_id:
            BOOKS.remove(book)
            return True
    return False

2.18 Books.vue增加更新操作

template部分增加:

<!-- edit book modal -->
<div
  ref="editBookModal"
  class="modal fade"
  :class="{ show: activeEditBookModal, 'd-block': activeEditBookModal }"
  tabindex="-1"
  role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">Update</h5>
        <button
          type="button"
          class="close"
          data-dismiss="modal"
          aria-label="Close"
          @click="toggleEditBookModal">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <form>
          <div class="mb-3">
            <label for="editBookTitle" class="form-label">Title:</label>
            <input
              type="text"
              class="form-control"
              id="editBookTitle"
              v-model="editBookForm.title"
              placeholder="Enter title">
          </div>
          <div class="mb-3">
            <label for="editBookAuthor" class="form-label">Author:</label>
            <input
              type="text"
              class="form-control"
              id="editBookAuthor"
              v-model="editBookForm.author"
              placeholder="Enter author">
          </div>
          <div class="mb-3 form-check">
            <input
              type="checkbox"
              class="form-check-input"
              id="editBookRead"
              v-model="editBookForm.read">
            <label class="form-check-label" for="editBookRead">Read?</label>
          </div>
          <div class="btn-group" role="group">
            <button
              type="button"
              class="btn btn-primary btn-sm"
              @click="handleEditSubmit">
              Submit
            </button>
            <button
              type="button"
              class="btn btn-danger btn-sm"
              @click="handleEditCancel">
              Cancel
            </button>
          </div>
        </form>
      </div>
    </div>
  </div>
</div>
<div v-if="activeEditBookModal" class="modal-backdrop fade show"></div>

script部分增加:

activeEditBookModal: false,
editBookForm: {
  id: '',
  title: '',
  author: '',
  read: [],
},

template部分的主界面修改:

<button
  type="button"
  class="btn btn-warning btn-sm"
  @click="toggleEditBookModal(book)">
  Update
</button>

script部分增加函数:

toggleEditBookModal(book) {
  if (book) {
    this.editBookForm = book;
  }
  const body = document.querySelector('body');
  this.activeEditBookModal = !this.activeEditBookModal;
  if (this.activeEditBookModal) {
    body.classList.add('modal-open');
  } else{
    body.classList.remove('modal-open');
  }
},

handleEditSubmit() {
  this.toggleEditBookModal(null);
  let read = false;
  if (this.editBookForm.read) read = true;
  const payload = {
    title: this.editBookForm.title,
    author: this.editBookForm.author,
    read,
  };
  this.updateBook(payload, this.editBookForm.id);
},

updateBook(payload, bookID) {
  const path = `http://localhost:5001/books/${bookID}`;
  axios.put(path, payload)
    .then(() => {
      this.getBooks();
      this.message = 'Book updated!';
      this.showMessage = true;
    })
    .catch((error) => {
      console.error(error);
      this.getBooks();
    });
},

handleEditCancel() {
  this.toggleEditBookModal(null);
  this.initForm();
  this.getBooks(); // why?
},

修改函数initForm():

initForm() {
  this.addBookForm.title = '';
  this.addBookForm.author = '';
  this.addBookForm.read = [];
  this.editBookForm.id = '';
  this.editBookForm.title = '';
  this.editBookForm.author = '';
  this.editBookForm.read = [];
},

浏览器预览如下:
在这里插入图片描述

结语

如果您觉得该方法或代码有一点点用处,可以给作者点个赞,或打赏杯咖啡;╮( ̄▽ ̄)╭
如果您感觉方法或代码不咋地//(ㄒoㄒ)//,就在评论处留言,作者继续改进;o_O???
如果您需要相关功能的代码定制化开发,可以留言私信作者;(✿◡‿◡)
感谢各位大佬童鞋们的支持!( ´ ▽´ )ノ ( ´ ▽´)っ!!!

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

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

相关文章

什么是ChatGPT?怎么用?

最近全网爆火的黑科技&#xff0c;叫做chatGPT。ChatGPT声称&#xff0c;它的AI对话模型能在大范围、细粒度问题上给出普遍准确的答案。简单地说&#xff0c;AI对话模型可以达到基本不犯错误的水平了。那么到底这个ChatGPT是什么&#xff1f;怎么用&#xff1f;本篇文章就来带大…

算法修炼之练气篇——练气二层

博主&#xff1a;命运之光 专栏&#xff1a;算法修炼之练气篇 题目 1084: 用筛法求之N内的素数 题目描述 用筛法求之N内的素数。 输入格式 N 输出格式 0&#xff5e;N的素数 样例输入 100 样例输出 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 …

学系统集成项目管理工程师(中项)系列21a_整体管理(上)

1. 含义 1.1. 包括为识别、定义、组合、统一和协调各项目管理过程组的各种过程和活动而开展的工作&#xff0c;是项目管理中一项综合性和全局性的管理工作 2. 项目经理是整合者 2.1. 【21上选33】 2.1.1. 【19上选37】 2.1.2. 【22上选33】 2.2. 通过与项目干系人主动、全…

shell脚本(磁盘空间、服务状态)

1、判断当前磁盘剩余空间是否有20G&#xff0c;如果小于20G&#xff0c;则将报警邮件发送给管理员&#xff0c;每天检查一次磁盘剩余空间。 第一步&#xff1a;创建脚本名为shell1.sh如下&#xff1a; vim shell1.sh 第二步&#xff1a;做计划在shell1文件中&#xff0c;命令…

Kyligence Zen 简直就是一站式指标平台的天花板

一、Kyligence Zen是什么&#xff1f; 1、Kyligence Zen是做啥的&#xff1f; Kyligence Zen是一款指标分析和管理的工具&#xff0c;是基于 Kyligence 核心 OLAP 能力打造&#xff0c;Kyligence Zen 提供集业务模型、指标管理、指标加工、数据服务于一体的一站式服务&#x…

孙溟㠭20余载春秋,4000多方印章,这双质朴的手有多么倔强的生命力

作品的背后往往折射出艺术家人生的广度和厚度。 先锋篆刻、书画艺术家孙溟㠭&#xff0c; 上世纪90年代开始接触篆刻&#xff0c; 至今&#xff0c;20载有余&#xff0c;积累了4000多方篆刻作品。 在他创作纪念吴品超院士的作品《药生尘》时&#xff0c; 我们拍到了艺术家…

高级Web题库

高级Web题库 For ZPT 声明 一切开发旨在学习&#xff0c;请勿用于非法用途 by rick rick 关注 永雏塔菲喵 永雏塔菲喵 选择题 第1题 知识点&#xff1a;CSS 题目&#xff1a;设置text-decoration属性的删除线的值为&#xff08; &#xff09;。 选项&#xff1a; A underlin…

固定翼无人机培训第二周总结——多轴和起降

博主学的III类固定翼垂直起降无人机&#xff0c;起降采用多旋翼&#xff08;下图中红框就是旋翼&#xff09;&#xff0c;巡航采用固定翼。 理论大部分也是多旋翼&#xff0c;多轴旋翼无人机是指三个旋翼轴及以上的特殊直升机&#xff0c;多旋翼无人机靠旋翼速度和方向来控制无…

代码随想录算法训练营第三十八天 | 动态规划基础流程

动态规划理论基础 代码随想录 (programmercarl.com) 如果某一问题有很多重叠子问题&#xff0c;使用动态规划是最有效的。 所以动态规划中每一个状态一定是由上一个状态推导出来的&#xff0c;这一点就区分于贪心&#xff0c;贪心没有状态推导&#xff0c;而是从局部直接选最…

Java结合POI框架实现Excel导入

Java结合POI框架实现Excel导入 一、流程概念二、conroller中的方法三、导入成功 一、流程概念 我们需要把excel通过上传得方式导入数据库&#xff0c;需要以下几个步骤 将excel上传到服务器指定文件夹内并重命名&#xff08;upload&#xff09;获取到文件公共路径和别名路径将…

InsCode再进步,AI 辅助编程帮你打开思路

文章目录 一、前言二、使用 AI 辅助完成代码1. 基于模板创建项目2. 使用 AI 辅助开拓思路3. 使用 AI 辅助生成代码4. 使用 AI 辅助优化代码 三、InsCode AI Chat 的使用建议四、总结 一、前言 你好&#xff0c;我是小雨青年&#xff0c;一名独立开发的程序员。 在之前的文章中…

Ubuntu22.04安装PyTorch1.13.0 GPU版本

目录 一、电脑相关信息 1. 电脑显卡环境&#xff1a; 二、安装Pytorch1.13.0/cu117&#xff08;GPU版本&#xff09; 1. 准备&#xff1a;新建虚拟环境 2. 用conda在线安装pytorch1.13.0/cu117&#xff08;pytorch1.13.0 torchvision0.14.0 pytorch-cuda11.7&#xff09;…

博客管理系统前端分析

目录结构博客列表页&#xff1a;所有页面共同的样式代码&#xff1a;博客详情页博客登录页博客编辑页 目录结构 博客列表页&#xff1a; 页面效果&#xff1a; 代码&#xff1a; <!-- 博客列表页 --> <!DOCTYPE html> <html lang"en"> <head…

计算机视觉的深度学习 Lecture4:Optimization 笔记 EECS 498.008

数值计算梯度 问题是慢&#xff0c;每个都要注意做步长&#xff0c;求除法。 应该用求导方法解决。 SGD通过每次抽取一部分&#xff08;mini-batch&#xff09;来计算梯度&#xff0c;而不是遍历整个数据集来求梯度&#xff0c;大大增大了求梯度速度&#xff0c;并且性能不…

TCP 协议特性详解

TCP 协议特性总结 TCP协议特点TCP协议段格式TCP原理确认应答&#xff08;安全机制&#xff09;超时重传&#xff08;安全机制&#xff09;连接管理&#xff08;安全机制&#xff09;(面试高频题)三次握手四次挥手 滑动窗口&#xff08;效率机制&#xff09;流量控制&#xff08…

【LeetCode】数据结构题解(8)[链表中的入口节点]

链表中的入口节点 1.题目来源2.题目描述3.解题思路4.代码展示 1.题目来源 链表中的入口节点 2.题目描述 给定一个链表&#xff0c;返回链表开始入环的第一个节点。 从链表的头节点开始沿着 next 指针进入环的第一个节点为环的入口节点。如果链表无环&#xff0c;则返回 null…

08-HTML-样式和语意标签

1、<style> 标签用于为 HTML 文档定义样式信息。type 属性是必需的&#xff0c;定义 style 元素的内容。唯一可能的值是 "text/css"。style 元素位于 head 部分中。 2、<div> 可定义文档中的分区或节&#xff08;division/section&#xff09;。<div&…

Unity Audio -- (4)为声音添加特殊效果

本节我们使用声音混响区域&#xff08;audio reverb zone&#xff09;实现一些特殊效果。 什么是混响区域&#xff08;audio reverb zone&#xff09; 不同障碍物对声波的反射和吸收能力不同&#xff0c;坚硬平整表面反射声波能力强&#xff0c;松软多孔的表面吸收声波能力强。…

yolov5环境搭建(Anaconda-py3.9、PyTorch-CPU、yolov5-4.0、PyCharm)

1.环境准备 Windows 10Anaconda&#xff08;基于Python3.9&#xff09;&#xff0c;已配置好环境变量yolov5相关的代码、权重文件等&#xff0c;已经打包整理好&#xff0c;可以通过百度网盘绿色下载。链接: https://pan.baidu.com/s/1okVkfpqjI5wD6PigK-AH0w?pwdyscw 提取码…

RabbitMQ发布/订阅(交换机)

目录 RabbitMQ发布/订阅(交换机)介绍Fanout&#xff08;广播&#xff09;声明队列和交换机publisher 消息发送consumer消息接收 Direct&#xff08;定向&#xff09;consumer消息接收,基于注解声明队列和交换机publisher 消息发送总结 Topic&#xff08;通配符&#xff09;publ…