Django框架的前端部分使用Ajax請求一

Ajax請求

目錄

1.ajax請求使用

2.增加任務列表功能(只有查看和新增)

3.代碼展示集合

這篇文章, 要開始講關于ajax請求的內容了。這個和以前文章中寫道的Vue框架里面的axios請求, 很相似。后端代碼, 會有一些細節點, 跟前幾節文章寫的有些區別。

一、ajax請求使用

我們先在templates文件夾下面新建ajax_data文件夾, 然后再創建ajax_data.html文件。

我們先講ajax使用的方法:

$.ajax({//請求的目標地址url: "/demo/one/",// 請求類型type:"post",// 表單數據data:{sign: "45z6x4c65qf4c4c5z",type: "text"},//請求成功后,接受目標函數的數據success:function (res){// 這里面需要寫請求成功之后, 需要做的事情console.log(res);}
})

說完ajax請求后, 我們需要寫關于ajax使用的代碼:

編輯ajax_data.html:

{% extends "index/model_tmp.html" %}{% block content %}<div class="container"><h1>Ajax演示-one</h1><input type="button" id="button-one" class="btn btn-success" value="點我"><table border="1" class="table"><thead><th>分類</th><th>名稱</th><th>最高價</th><th>最低價</th><th>平均價</th><th>產地</th></thead><tbody id="tBody"></tbody></table><h1>Ajax演示-two</h1><input type="text" id="username" placeholder="請輸入賬號"><input type="password" id="password" placeholder="請輸入密碼"><input type="button" id="button-two" class="btn btn-success" value="點我"></div>
{% endblock %}{% block js %}<script>$(function () {bindBtnOne();bindBtnTwo();})function bindBtnOne() {$("#button-one").click(function () {$.ajax({//請求的目標地址url: "/demo/one/",// 請求類型type:"post",// 表單數據data:{sign: "45z6x4c65qf4c4c5z",type: "text"},//請求成功后,接受目標函數的數據success:function (res){//獲取dict_data當中list所對于的值var list = res.list;var htmlStr = "";for (var i=0; i<list.length;i++){// emp相當于dict_data[list]當中的每一個字典var emp = list[i];//每次循環的時候,向頁面添加一行六列htmlStr += "<tr>";htmlStr += "<td>"+emp.prodCat+"</td>";htmlStr += "<td>"+emp.prodName+"</td>";htmlStr += "<td>"+emp.highPrice+"</td>";htmlStr += "<td>"+emp.lowPrice+"</td>";htmlStr += "<td>"+emp.avgPrice+"</td>";htmlStr += "<td>"+emp.place+"</td>";htmlStr += "</tr>";document.getElementById("tBody").innerHTML = htmlStr;}}})})}function bindBtnTwo() {$("#button-two").click(function () {$.ajax({url:"/demo/two/",type:"post",data:{username:$("#username").val(),password:$("#password").val(),},success:function (res){//alert(res)alert(res.status)}})})}</script>
{% endblock %}

這里面有兩個ajax請求, 第一個是通過點擊按鈕來獲取后端數據完成ajax請求, 最后我們把數據放在tbody標簽里面顯示, 第二個是通過判斷賬號密碼兩個輸入框里面的內容, 是否包含在賬號數據表里面, 如果有, 那就返回true, 否則就返回false。后端代碼的邏輯, 會在后面寫道。

我們在views里面創建Ajax_data.py:

Ajax_data.py代碼:

from django.http import JsonResponse
from django.shortcuts import render, redirect
from django.views.decorators.csrf import csrf_exempt# Create your views here.
def demo_list(request):return render(request, "ajax_data/ajax_data.html")@csrf_exempt
def demo_one(request):dict_data = {"current": 1,"limit": 20,"count": 129705,"list": [{"id": 1724017,"prodName": "大白菜","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "0.4","highPrice": "0.55","avgPrice": "0.48","place": "冀魯豫鄂","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1724016,"prodName": "娃娃菜","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "0.65","highPrice": "0.75","avgPrice": "0.7","place": "豫","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1724015,"prodName": "小白菜","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "1.0","highPrice": "1.2","avgPrice": "1.1","place": "冀","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1724014,"prodName": "圓白菜","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "0.55","highPrice": "1.4","avgPrice": "0.98","place": "冀鄂魯","specInfo": "甘藍","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1724013,"prodName": "紫甘藍","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "2.3","highPrice": "2.4","avgPrice": "2.35","place": "冀蘇","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1724012,"prodName": "芹菜","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "1.2","highPrice": "1.4","avgPrice": "1.3","place": "魯","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1724011,"prodName": "西芹","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "1.6","highPrice": "2.0","avgPrice": "1.8","place": "魯遼","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1724010,"prodName": "菠菜","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "1.2","highPrice": "1.5","avgPrice": "1.35","place": "魯冀","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1724009,"prodName": "萵筍","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "1.5","highPrice": "1.9","avgPrice": "1.7","place": "魯","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1724008,"prodName": "團生菜","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "2.5","highPrice": "3.5","avgPrice": "3.0","place": "云冀","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1724007,"prodName": "羅馬生菜","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "3.0","highPrice": "3.3","avgPrice": "3.15","place": "云","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1724006,"prodName": "散葉生菜","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "2.0","highPrice": "2.5","avgPrice": "2.25","place": "遼冀京","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1724005,"prodName": "油菜","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "1.2","highPrice": "1.5","avgPrice": "1.35","place": "皖川京魯","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1724004,"prodName": "香菜","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "2.0","highPrice": "2.5","avgPrice": "2.25","place": "冀","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1724003,"prodName": "茴香","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "2.0","highPrice": "2.5","avgPrice": "2.25","place": "冀","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1724002,"prodName": "韭菜","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "2.0","highPrice": "2.8","avgPrice": "2.4","place": "冀粵","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1724001,"prodName": "苦菊","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "1.6","highPrice": "2.2","avgPrice": "1.9","place": "遼冀","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1724000,"prodName": "油麥菜","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "2.2","highPrice": "3.0","avgPrice": "2.6","place": "京冀","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1723999,"prodName": "散菜花","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "2.0","highPrice": "3.8","avgPrice": "2.9","place": "陜云豫","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1723998,"prodName": "綠菜花","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "2.3","highPrice": "2.8","avgPrice": "2.55","place": "蘇鄂浙","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"}]}return JsonResponse(dict_data)@csrf_exempt
def demo_two(request):dict_data = {"status": True}return JsonResponse(dict_data)

demo_one函數里面的dict_data里面的數據, 就是當前端點擊按鈕的時候, 就會去向后端發起請求, 請求成功以后, 將數據返回給前端, 并展示到前端的頁面上。

demo_two函數里面的dict_data里面的數據, 就是把status里面的布爾值傳遞給前端, 這個布爾值就代表判斷賬號密碼的是否在賬戶數據庫表格里面存在的意思, 這個邏輯, 我們會在下一篇文章, 具體寫關于賬號密碼判斷的邏輯。

還有, 這里面用了@csrf_exempt, 是因為在前端, 沒有寫form表單, 之前我們寫前端的時候, 都是有form表單, 然后在里面寫上post方法, 里面有csrf_token, 但是這里不一樣, 用到了ajax請求, 里面type也是post, 所以我們沒有在html里面寫csrf_token, 而是把這個驗證, 寫到了后端代碼里面。這就是和之前寫的代碼, 有小小的區別, 但代碼的意思都是差不多的。在用@csrf_exempt,之前, 需要導入包:from django.views.decorators.csrf import csrf_exempt。

這里面有個叫JsonResponse, 意思就是把傳進去的參數, 以json格式返回。之后前端請求到的數據, 就是json格式的數據了。

二、 增加任務列表功能(只有查看和新增)

首先, 我們需要先增加任務數據庫表格, 這個是毋庸置疑的。

models.py:

class Task(models.Model):title = models.CharField(verbose_name="標題", max_length=64)level_choice = {(1, "臨時任務"),(2, "普通任務"),(3, "重要任務"),(4, "緊急任務")}level = models.SmallIntegerField(verbose_name="任務級別", choices=level_choice)detail = models.TextField(verbose_name="任務內容")user = models.ForeignKey(verbose_name="負責人", to="UserInfo", on_delete=models.CASCADE, null=True, blank=True)times = models.DateField(verbose_name="開始時間")code_choices = {(1, "未完成"),(2, "正在處理"),(3, "已完成")}code = models.SmallIntegerField(verbose_name="任務狀態", choices=code_choices)

然后在項目對應的目錄下, 執行python manage.py makemigrationspython manage.py migrate這兩行代碼。

接著, 我們在templates里面創建task_data.html文件。

task_data.html:

{% extends "index/model_tmp.html" %}{% block content %}<div class="container"><div class="panel panel-success"><div class="panel-heading"><h3 class="panel-title">添加任務</h3></div><div class="panel-body"><div class="form-group"><form id="formAdd">{% for filed in form %}<div class="col-xs-6"><label for="exampleInputEmail1">{{ filed.label }}</label>{{ filed }}</div>{% endfor %}<div class="col-xs-12"><button type="button" id="button-add" class="btn btn-success">提交</button></div></form></div></div></div></div><div class="container"><div class="panel panel-success"><div class="panel-heading"><h3 class="panel-title">任務展示</h3></div><div class="panel-body"><table class="table table-bordered"><thead><tr><th>任務ID</th><th>任務標題</th><th>任務級別</th><th>任務內容</th><th>任務時間</th><th>任務狀態</th><th>任務負責人</th><th>操作</th></tr></thead><tbody>{% for data in queryset %}<tr><th>{{ data.id }}</th><th>{{ data.title }}</th><th>{{ data.get_level_display }}</th><th>{{ data.detail }}</th><th>{{ data.times }}</th><th>{{ data.get_code_display }}</th><th>{{ data.user.name }}</th></tr>{% endfor %}</tbody></table></div></div></div>
{% endblock %}{% block js %}<script>$(function (){bindBtnEvent();})function bindBtnEvent() {$("#button-add").click(function () {$.ajax({url :"/task/add/",type:"post",data:$("#formAdd").serialize(),dataType:"JSON",success:function (res){alert("添加成功")}})})}</script>
{% endblock %}

我們這里把添加和展示頁面, 都寫在同一個頁面上面了。

在views里面新建一個task_data.py:

task_data.py代碼:

from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
from django.shortcuts import render
from project_one import models
from django import forms# Create your views here.
class taskModelForm(forms.ModelForm):class Meta:model = models.Taskfields = '__all__'def __init__(self, *args, **kwargs):super(taskModelForm, self).__init__(*args, **kwargs)for item, field in self.fields.items():field.widget.attrs['class'] = 'form-control'field.widget.attrs['autocomplete'] = 'off'@csrf_exempt
def task_list(request):queryset = models.Task.objects.all()form = taskModelForm()content = {'form': form, "queryset": queryset}return render(request, "task_data/task_list.html", content)@csrf_exempt
def task_add(request):form = taskModelForm(request.POST)if form.is_valid():form.save()dict_data = {"status": True}return JsonResponse(dict_data)dict_data = {"status": False}return JsonResponse(dict_data)

task_list是展示任務的內容, task_add是添加任務的內容。

在task_add里面, dict_data的status的值, 是根據數據是否添加成功來決定的, 當數據添加成功的時候, dict_data的status的值為true, 反之就為false。

最后配置下路由:

urls.py:

"""project_simple URL ConfigurationThe `urlpatterns` list routes URLs to views. For more information please see:https://docs.djangoproject.com/en/4.1/topics/http/urls/
Examples:
Function views1. Add an import:  from my_app import views2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views1. Add an import:  from other_app.views import Home2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf1. Import the include() function: from django.urls import include, path2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from project_one.views import depart, user, assets, admin_role, login, Ajax_data, task_dataurlpatterns = [path("task/list/", task_data.task_list, name="task_list"),path("task/add/", task_data.task_add, name="task_add"),
]

我們不要忘記在model_tmp.html里面添加ajax請求和任務列表:

model_tmp.html:

<li class="dropdown">{% if request.unicom_role == 3 %}<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"aria-expanded="false">平臺用戶<span class="caret"></span></a>{% endif %}<ul class="dropdown-menu"><li><a href="/admin_list/">登錄賬號</a></li><li><a href="/demo/list/">ajax請求</a></li></ul>
</li>
<li class="active"><a href="/task/list/">任務列表</a></li>

運行結果:

點擊平臺用戶里面的ajax請求:

在這里插入圖片描述

點擊按鈕:

在這里插入圖片描述

請求成功:

在這里插入圖片描述

然后在下面的輸入框里面隨便輸入內容:

在這里插入圖片描述

點擊按鈕:

在這里插入圖片描述

由于我們在后端代碼里面沒有寫到判斷賬號密碼的邏輯, 所以它這里一直返回的是true, 這個問題, 會在下一篇文章, 里面寫道。

接著再點擊任務列表:

在這里插入圖片描述

上面填寫內容并提交:

在這里插入圖片描述

彈窗, 顯示添加成功:

在這里插入圖片描述

然后再刷新下網頁:

在這里插入圖片描述

我們發現, 數據添加成功。

三、代碼展示集合

前端:

ajax_data.html:

{% extends "index/model_tmp.html" %}{% block content %}<div class="container"><h1>Ajax演示-one</h1><input type="button" id="button-one" class="btn btn-success" value="點我"><table border="1" class="table"><thead><th>分類</th><th>名稱</th><th>最高價</th><th>最低價</th><th>平均價</th><th>產地</th></thead><tbody id="tBody"></tbody></table><h1>Ajax演示-two</h1><input type="text" id="username" placeholder="請輸入賬號"><input type="password" id="password" placeholder="請輸入密碼"><input type="button" id="button-two" class="btn btn-success" value="點我"></div>
{% endblock %}{% block js %}<script>$(function () {bindBtnOne();bindBtnTwo();})function bindBtnOne() {$("#button-one").click(function () {$.ajax({//請求的目標地址url: "/demo/one/",// 請求類型type:"post",// 表單數據data:{sign: "45z6x4c65qf4c4c5z",type: "text"},//請求成功后,接受目標函數的數據success:function (res){//獲取dict_data當中list所對于的值var list = res.list;var htmlStr = "";for (var i=0; i<list.length;i++){// emp相當于dict_data[list]當中的每一個字典var emp = list[i];//每次循環的時候,向頁面添加一行六列htmlStr += "<tr>";htmlStr += "<td>"+emp.prodCat+"</td>";htmlStr += "<td>"+emp.prodName+"</td>";htmlStr += "<td>"+emp.highPrice+"</td>";htmlStr += "<td>"+emp.lowPrice+"</td>";htmlStr += "<td>"+emp.avgPrice+"</td>";htmlStr += "<td>"+emp.place+"</td>";htmlStr += "</tr>";document.getElementById("tBody").innerHTML = htmlStr;}}})})}function bindBtnTwo() {$("#button-two").click(function () {$.ajax({url:"/demo/two/",type:"post",data:{username:$("#username").val(),password:$("#password").val(),},success:function (res){//alert(res)alert(res.status)}})})}</script>
{% endblock %}

task_data.html:

{% extends "index/model_tmp.html" %}{% block content %}<div class="container"><div class="panel panel-success"><div class="panel-heading"><h3 class="panel-title">添加任務</h3></div><div class="panel-body"><div class="form-group"><form id="formAdd">{% for filed in form %}<div class="col-xs-6"><label for="exampleInputEmail1">{{ filed.label }}</label>{{ filed }}</div>{% endfor %}<div class="col-xs-12"><button type="button" id="button-add" class="btn btn-success">提交</button></div></form></div></div></div></div><div class="container"><div class="panel panel-success"><div class="panel-heading"><h3 class="panel-title">任務展示</h3></div><div class="panel-body"><table class="table table-bordered"><thead><tr><th>任務ID</th><th>任務標題</th><th>任務級別</th><th>任務內容</th><th>任務時間</th><th>任務狀態</th><th>任務負責人</th><th>操作</th></tr></thead><tbody>{% for data in queryset %}<tr><th>{{ data.id }}</th><th>{{ data.title }}</th><th>{{ data.get_level_display }}</th><th>{{ data.detail }}</th><th>{{ data.times }}</th><th>{{ data.get_code_display }}</th><th>{{ data.user.name }}</th></tr>{% endfor %}</tbody></table></div></div></div>
{% endblock %}{% block js %}<script>$(function (){bindBtnEvent();})function bindBtnEvent() {$("#button-add").click(function () {$.ajax({url :"/task/add/",type:"post",data:$("#formAdd").serialize(),dataType:"JSON",success:function (res){alert("添加成功")}})})}</script>
{% endblock %}

model_tmp.html:

{% load static %}
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title><link rel="stylesheet" href="{% static 'css/bootstrap.css' %}">{% block css %}{% endblock %}
</head>
<body>
<div class="navbar navbar-default"><div class="container"><!-- Brand and toggle get grouped for better mobile display --><div class="navbar-header"><button type="button" class="navbar-toggle collapsed" data-toggle="collapse"data-target="#bs-example-navbar-collapse-1" aria-expanded="false"><span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button><a class="navbar-brand" href="#">管理系統</a></div><!-- Collect the nav links, forms, and other content for toggling --><div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"><ul class="nav navbar-nav">{% if request.unicom_role == 1 %}<li class="active"><a href="/depart/">部門頁面</a></li><li class="active"><a href="/user/">員工頁面</a></li>{% elif request.unicom_role == 3%}<li class="active"><a href="/depart/">部門頁面</a></li><li class="active"><a href="/user/">員工頁面</a></li><li class="active"><a href="/assets_list/">資產頁面</a></li>{% endif %}
{#                <li class="active"><a href="/depart/">部門頁面</a></li>#}
{#                <li class="active"><a href="/user/">員工頁面</a></li>#}
{#                <li class="active"><a href="/assets_list/">資產頁面</a></li>#}<li class="dropdown">{% if request.unicom_role == 3 %}<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"aria-expanded="false">平臺用戶<span class="caret"></span></a>{% endif %}<ul class="dropdown-menu"><li><a href="/admin_list/">登錄賬號</a></li><li><a href="/demo/list/">ajax請求</a></li></ul></li><li class="active"><a href="/task/list/">任務列表</a></li></ul><ul class="nav navbar-nav navbar-right"><li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"aria-expanded="false">歡迎-->{{ request.session.info.username }}<span class="caret"></span></a><ul class="dropdown-menu"><li><a href="/logout/">退出登錄</a></li></ul></li></ul></div><!-- /.navbar-collapse --></div><!-- /.container-fluid -->
</div>{% block content %}
{% endblock %}
<script src="{% static 'js/jquery3.7.1.js' %}"></script>
<script src="{% static 'js/bootstrap.js' %}"></script>
{% block js %}
{% endblock %}
</body>
</html>
后端:

models.py:

from django.db import models# Create your models here.
class Department(models.Model):title = models.CharField(verbose_name="部門名稱", max_length=255)def __str__(self):return self.titleclass UserInfo(models.Model):name = models.CharField(verbose_name="姓名", max_length=255)gender_choices = ((1, "男"), (2, "女"))gender = models.SmallIntegerField(verbose_name="性別", choices=gender_choices)salary = models.IntegerField(verbose_name="薪水")age = models.IntegerField(verbose_name="年齡")create_time = models.DateField(verbose_name="入職時間")department = models.ForeignKey(verbose_name="部門", max_length=255, to="Department", to_field="id",on_delete=models.CASCADE, null=True, blank=True)def __str__(self):return self.nameclass Assets(models.Model):mobile = models.CharField(verbose_name="手機號", max_length=11)status_code_choice = ((1, "已使用"),(2, "未使用"))status = models.SmallIntegerField(verbose_name="狀態", choices=status_code_choice)create_time = models.DateField(verbose_name="創建時間")user = models.ForeignKey(to="UserInfo", to_field="id", verbose_name="使用者", on_delete=models.SET_NULL, null=True, blank=True)price = models.CharField(verbose_name="價格", max_length=10)class AdminRole(models.Model):username = models.CharField(verbose_name="用戶名", max_length=32)password = models.CharField(verbose_name="密碼", max_length=64)password_choice = ((1, "員工"),(2, "領導"),(3, "管理員"))role = models.SmallIntegerField(verbose_name="角色", choices=password_choice)class Task(models.Model):title = models.CharField(verbose_name="標題", max_length=64)level_choice = {(1, "臨時任務"),(2, "普通任務"),(3, "重要任務"),(4, "緊急任務")}level = models.SmallIntegerField(verbose_name="任務級別", choices=level_choice)detail = models.TextField(verbose_name="任務內容")user = models.ForeignKey(verbose_name="負責人", to="UserInfo", on_delete=models.CASCADE, null=True, blank=True)times = models.DateField(verbose_name="開始時間")code_choices = {(1, "未完成"),(2, "正在處理"),(3, "已完成")}code = models.SmallIntegerField(verbose_name="任務狀態", choices=code_choices)

Ajax_data.py:

from django.http import JsonResponse
from django.shortcuts import render, redirect
from django.views.decorators.csrf import csrf_exempt# Create your views here.
def demo_list(request):return render(request, "ajax_data/ajax_data.html")@csrf_exempt
def demo_one(request):dict_data = {"current": 1,"limit": 20,"count": 129705,"list": [{"id": 1724017,"prodName": "大白菜","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "0.4","highPrice": "0.55","avgPrice": "0.48","place": "冀魯豫鄂","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1724016,"prodName": "娃娃菜","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "0.65","highPrice": "0.75","avgPrice": "0.7","place": "豫","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1724015,"prodName": "小白菜","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "1.0","highPrice": "1.2","avgPrice": "1.1","place": "冀","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1724014,"prodName": "圓白菜","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "0.55","highPrice": "1.4","avgPrice": "0.98","place": "冀鄂魯","specInfo": "甘藍","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1724013,"prodName": "紫甘藍","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "2.3","highPrice": "2.4","avgPrice": "2.35","place": "冀蘇","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1724012,"prodName": "芹菜","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "1.2","highPrice": "1.4","avgPrice": "1.3","place": "魯","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1724011,"prodName": "西芹","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "1.6","highPrice": "2.0","avgPrice": "1.8","place": "魯遼","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1724010,"prodName": "菠菜","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "1.2","highPrice": "1.5","avgPrice": "1.35","place": "魯冀","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1724009,"prodName": "萵筍","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "1.5","highPrice": "1.9","avgPrice": "1.7","place": "魯","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1724008,"prodName": "團生菜","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "2.5","highPrice": "3.5","avgPrice": "3.0","place": "云冀","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1724007,"prodName": "羅馬生菜","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "3.0","highPrice": "3.3","avgPrice": "3.15","place": "云","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1724006,"prodName": "散葉生菜","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "2.0","highPrice": "2.5","avgPrice": "2.25","place": "遼冀京","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1724005,"prodName": "油菜","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "1.2","highPrice": "1.5","avgPrice": "1.35","place": "皖川京魯","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1724004,"prodName": "香菜","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "2.0","highPrice": "2.5","avgPrice": "2.25","place": "冀","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1724003,"prodName": "茴香","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "2.0","highPrice": "2.5","avgPrice": "2.25","place": "冀","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1724002,"prodName": "韭菜","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "2.0","highPrice": "2.8","avgPrice": "2.4","place": "冀粵","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1724001,"prodName": "苦菊","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "1.6","highPrice": "2.2","avgPrice": "1.9","place": "遼冀","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1724000,"prodName": "油麥菜","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "2.2","highPrice": "3.0","avgPrice": "2.6","place": "京冀","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1723999,"prodName": "散菜花","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "2.0","highPrice": "3.8","avgPrice": "2.9","place": "陜云豫","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"},{"id": 1723998,"prodName": "綠菜花","prodCatid": 1186,"prodCat": "蔬菜","prodPcatid": "null","prodPcat": "","lowPrice": "2.3","highPrice": "2.8","avgPrice": "2.55","place": "蘇鄂浙","specInfo": "","unitInfo": "斤","pubDate": "2024-12-31 00:00:00","status": "null","userIdCreate": 138,"userIdModified": "null","userCreate": "admin","userModified": "null","gmtCreate": "null","gmtModified": "null"}]}return JsonResponse(dict_data)@csrf_exempt
def demo_two(request):dict_data = {"status": True}return JsonResponse(dict_data)

task_data.py:

from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
from django.shortcuts import render
from project_one import models
from django import forms# Create your views here.
class taskModelForm(forms.ModelForm):class Meta:model = models.Taskfields = '__all__'def __init__(self, *args, **kwargs):super(taskModelForm, self).__init__(*args, **kwargs)for item, field in self.fields.items():field.widget.attrs['class'] = 'form-control'field.widget.attrs['autocomplete'] = 'off'@csrf_exempt
def task_list(request):queryset = models.Task.objects.all()form = taskModelForm()content = {'form': form, "queryset": queryset}return render(request, "task_data/task_list.html", content)@csrf_exempt
def task_add(request):form = taskModelForm(request.POST)if form.is_valid():form.save()dict_data = {"status": True}return JsonResponse(dict_data)dict_data = {"status": False}return JsonResponse(dict_data)

urls.py:

"""project_simple URL ConfigurationThe `urlpatterns` list routes URLs to views. For more information please see:https://docs.djangoproject.com/en/4.1/topics/http/urls/
Examples:
Function views1. Add an import:  from my_app import views2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views1. Add an import:  from other_app.views import Home2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf1. Import the include() function: from django.urls import include, path2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from project_one.views import depart, user, assets, admin_role, login, Ajax_data, task_dataurlpatterns = [# path('admin/', admin.site.urls),path("", depart.index, name="index"),path("depart/", depart.depart, name="depart"),path("depart/add/", depart.add_depart, name="add_depart"),path("depart/<int:nid>/modify/", depart.depart_modify, name="depart_modify"),path("depart/<int:nid>/del/", depart.del_depart, name="del_depart"),path("user/", user.user_info, name="user_info"),path("user/add/", user.user_add, name="user_add"),path("user/<int:nid>/modify/", user.user_modify, name="user_modify"),path("user/<int:nid>/del/", user.user_del, name="user_del"),path("user/add/modelform", user.user_add_modelform, name="user_add_modelform"),path("user/<int:nid>/modify/modelform", user.user_modify_modelform, name="user_modify_modelform"),path("assets_list/", assets.assets, name="assets"),path("assets/add/", assets.assets_add, name="assets_add"),path("assets/<int:nid>/modify/", assets.assets_modify, name="assets_modify"),path("assets/<int:nid>/del/", assets.assets_del, name="assets_del"),path("admin_list/", admin_role.admin, name="admin"),path("admin/add/", admin_role.admin_add, name="admin_add"),path("admin/<int:nid>/modify/", admin_role.admin_modify, name="admin_modify"),path("admin/<int:nid>/reset/pwd/", admin_role.admin_reset_pwd, name="admin_reset_pwd"),path("admin/<int:nid>/del/", admin_role.admin_del, name="admin_del"),path("login/", login.login, name="login"),path("logout/", login.logout, name="logout"),path("image/code/", login.image_code, name="image_code"),path("demo/list/", Ajax_data.demo_list, name="demo_list"),path("demo/one/", Ajax_data.demo_one, name="demo_one"),path("demo/two/", Ajax_data.demo_two, name="demo_two"),path("task/list/", task_data.task_list, name="task_list"),path("task/add/", task_data.task_add, name="task_add"),
]

好了, 關于django框架里面的ajax請求使用的內容, 就到此為止了。這個ajax使用, 和Vue框架里面的axios差不多, 還有一些后端代碼, 有些寫法和之前的不一樣, 可以和前面文章寫的后端代碼進行對比學習!!!

以上就是Django框架里面的ajax請求使用的所有內容了, 如果有哪里不懂的地方,可以把問題打在評論區, 歡迎大家在評論區交流!!!
如果我有寫錯的地方, 望大家指正, 也可以聯系我, 讓我們一起努力, 繼續不斷的進步.
學習是個漫長的過程, 需要我們不斷的去學習并掌握消化知識點, 有不懂或概念模糊不理解的情況下,一定要趕緊的解決問題, 否則問題只會越來越多, 漏洞也就越老越大.
人生路漫漫, 白鷺常相伴!!!

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/bicheng/81628.shtml
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/81628.shtml
英文地址,請注明出處:http://en.pswp.cn/bicheng/81628.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

IP地址代理公司:服務模式與行業應用探析

隨著數據驅動型經濟的快速發展和互聯網應用的普及&#xff0c;IP地址代理服務逐漸成為支持多種網絡業務的重要組成部分。近年來&#xff0c;提供代理IP服務的公司遍地開花&#xff0c;這一市場強調供給的技術深度和服務靈活性&#xff0c;而代理IP公司本身也逐步從單一的技術供…

C語言練手磨時間

167. 兩數之和 II - 輸入有序數組 給你一個下標從 1 開始的整數數組 numbers &#xff0c;該數組已按 非遞減順序排列 &#xff0c;請你從數組中找出滿足相加之和等于目標數 target 的兩個數。如果設這兩個數分別是 numbers[index1] 和 numbers[index2] &#xff0c;則 1 <…

本地部署Firecrawl+Dify調用踩坑記錄

最近自己研究Dify&#xff0c;使用到Firecrawl這個比較好用的工具。用Firecrawl官網的不知道為什么總是卡住得不到結果&#xff0c;于是我打算自己去本地部署一個。好家伙真給我人搞麻了&#xff0c;太多問題了。 我是在京東云上面租的一臺服務器。 首先就是docker的安裝&…

iOS SwiftUI的具體運用實例(SwiftUI庫的運用)

最近接觸到一個 SwiftUI的第三方框架&#xff0c;它非常的好用。以下是 具體運用實例&#xff0c;結合其核心功能與開發場景&#xff0c;分多個維度進行詳細解析&#xff1a; 一、基礎 UI 組件開發 登錄界面 SwiftUI 的 VStack、TextField 和 Button 可快速構建用戶登錄表單。例…

【C++】模板上(泛型編程) —— 函數模板與類模板

文章目錄 一、啥是泛型編程二、函數模板2.1、函數模板的概念2.2、函數模板的格式2.3、函數模板的原理2.4、函數模板的實例化2.4.1、隱式實例化&#xff1a;讓編譯器根據實參推演模板參數的實際類型2.4.2、顯示實例化&#xff1a;在函數名后的<>中指定模板參數的實際類型 …

語音識別-2

目錄 1.藍牙優化 1.打開sco 2.外放時的藍牙的不同版本適配 2.微軟文本轉語音優化 1.異步文本轉語音 2.語音的個性化 上一篇關于語音識別, 雖然能用,但在系統適配,機器適配方面,速度,性能等還是有優化的地方.所以這篇是關于這些的. 1.藍牙優化 A2DP:是一種單向的高品質音…

【springcloud學習(dalston.sr1)】服務消費者通過restTemplate來訪問服務提供者(含源代碼)(五)

該系列項目整體介紹及源代碼請參照前面寫的一篇文章??????【springcloud學習(dalston.sr1)】項目整體介紹&#xff08;含源代碼&#xff09;&#xff08;一&#xff09; springcloud學習&#xff08;dalston.sr1&#xff09;系統文章匯總如下&#xff1a; 【springcloud…

小白學編程之——數據庫如何性能優化

小白學編程之——數據庫性能優化指南 數據庫如同一個大型倉庫&#xff0c;性能優化就是幫助倉庫管理員&#xff08;數據庫&#xff09;更高效地存取貨物&#xff08;數據&#xff09;。本文將以通俗易懂的方式&#xff0c;帶你避開常見誤區&#xff0c;讓數據庫運行得更快更穩…

SQLMesh信號機制詳解:如何精準控制模型評估時機

SQLMesh的信號機制為數據工程師提供了更精細的模型評估控制能力。本文深入解析信號機制的工作原理&#xff0c;通過簡單和高級示例展示如何自定義信號&#xff0c;并提供實用的使用技巧和測試方法&#xff0c;幫助讀者優化數據管道的調度效率。 一、為什么需要信號機制&#xf…

FreeSWITCH 簡單圖形化界面43 - 使用百度的unimrcp搞個智能話務臺,用的在線的ASR和TTS

FreeSWITCH 簡單圖形化界面43 - 使用百度的unimrcp搞個智能話務臺 0、一個fs的web配置界面預覽1、安裝unimrcp模塊2、安裝完成后&#xff0c;配置FreeSWITCH。2.1 有界面的配置2.1.1 mod_unimrcp模塊配置2.1.2 mod_unimrcp客戶端配置 2.2 無界面的配置 3、呼叫規則4、編寫流程4…

【架構】RUP統一軟件過程:企業級軟件開發的全面指南

一、RUP概述 RUP(Rational Unified Process&#xff0c;統一軟件過程)是由Rational Software公司(后被IBM收購)開發的一種迭代式軟件開發過程框架。它結合了傳統瀑布模型的系統性和敏捷方法的靈活性&#xff0c;為中大型軟件項目提供了全面的開發方法論。 RUP不僅僅是一種過程…

DeepSeek賦能電商,智能客服機器人破解大型活動人力困境

1. DeepSeek 與電商客服結合的背景 1.1 電商行業客服需求特點 電商行業具有獨特的客服需求特點&#xff0c;這些特點決定了智能客服機器人在該行業的必要性和重要性。 高并發性&#xff1a;電商平臺的用戶數量龐大&#xff0c;尤其是在促銷活動期間&#xff0c;用戶咨詢量會…

面向具身智能的視覺-語言-動作模型(VLA)綜述

具身智能被廣泛認為是通用人工智能&#xff08;AGI&#xff09;的關鍵要素&#xff0c;因為它涉及控制具身智能體在物理世界中執行任務。在大語言模型和視覺語言模型成功的基礎上&#xff0c;一種新的多模態模型——視覺語言動作模型&#xff08;VLA&#xff09;已經出現&#…

后端框架(1):Mybatis

什么是框架&#xff1f; 蓋高樓&#xff0c;框架結構。 框架結構就是高樓的主體&#xff0c;基礎功能。 把很多基礎功能已經實現了(封裝了)。 在基礎語言之上&#xff0c;對各種基礎功能進行封裝&#xff0c;方便開發者&#xff0c;提高開發效率。 mybatis&#xff1a;對jd…

ubuntu20.04系統搭建k8s1.28集群-docker作為容器運行時

ubuntu系統搭建 ubuntu-22.04.5-desktop-amd64.iso映像文件--->實際卻是20.4focal版本。 【安裝過程沒有特別指出的默認回車下一步】 【用戶和密碼設置】 【網絡連接】 【在vmware上安裝的話&#xff0c;網絡配置如下】【在vm里配置選擇nat或者橋接即可】 【國內源配置】&…

軟件I2C

軟件I2C 注意&#xff1a; SDA&#xff08;串行數據線&#xff09;和SCL&#xff08;串行時鐘線&#xff09;都是雙向I/O線&#xff0c;接口電路為開漏輸出。需通過上拉電阻接電源VCC。 軟件I2C說明 說明&#xff0c;有的單片機沒有硬件I2C的功能&#xff0c;或者因為電路設計…

C++性能測試工具——Vtune的使用

一、Intel Vtune的安裝 在前面初步認識了一下幾個性能的測試工具&#xff0c;本篇重點介紹一下Intel VTune Profiler&#xff0c;VTune是一個強大的性能分析工具&#xff0c;它屬于Intel oneAPI工具包中工具的一種。VTune的安裝只介紹在Linux平臺下的場景&#xff08;Windows安…

互聯網大廠Java求職面試:優惠券服務架構設計與AI增強實踐-6

互聯網大廠Java求職面試&#xff1a;優惠券服務架構設計與AI增強實踐-6 場景設定&#xff1a;技術總監張總坐在會議室里&#xff0c;鄭薪苦帶著自信的微笑走了進來。今天他們要圍繞優惠券服務的架構設計及如何結合AI進行增強展開討論。 第一輪面試&#xff1a;基礎架構設計 …

nginx模塊使用、過濾器模塊以及handler模塊

一、如何使用nginx的模塊 1.ngx_code.c: #include "ngx_config.h" #include "ngx_conf_file.h" #include "nginx.h" #include "ngx_core.h" #include "ngx_string.h" #include "ngx_palloc.h" #include "n…

【Odoo】Pycharm導入運行Odoo15

【Odoo】Pycharm導入運行Odoo15 前置準備1. Odoo-15項目下載解壓2. PsrtgreSQL數據庫 項目導入運行1. 項目導入2. 設置項目內虛擬環境3. 下載項目中依賴4. 修改配置文件odoo.conf 運行Pycharm快捷運行 前置準備 1. Odoo-15項目下載解壓 將下載好的項目解壓到開發目錄下 2. …