标签:方式 imp admin res 设置 host strong cti connect
redis_pool.py
import redis Pool= redis.ConnectionPool(host=‘localhost‘, port=6379)
urls.py
from django.contrib import admin from django.urls import path from myapp import views urlpatterns = [ path(‘admin/‘, admin.site.urls), path(‘index/‘, views.index), path(‘home/‘, views.home), ]
views.py
from django.shortcuts import render,HttpResponse import redis from uits.redis_pool import # Pool 引入连接池 def index(request): conn = redis.Redis(connection_pool=Pool) conn.hset("k1","age",18) return HttpResponse("这是设置值") def home(request): conn = redis.Redis(connection_pool=Pool) aa=conn.hget("k1","age") print(aa) return HttpResponse("获取值")
标签:方式 imp admin res 设置 host strong cti connect
原文地址:https://www.cnblogs.com/lovershowtime/p/11717032.html