上一页 1 2 3 4 5 6 7 ··· 12 下一页
摘要: 1.ORM操作: 1.创建数据库'db4_16' 2.在settings.py中把django的默认数据库sqlite修改为mysql DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'db4_16', 阅读全文
posted @ 2020-04-20 16:23 梁劲雄 阅读(202) 评论(0) 推荐(0) 编辑
摘要: 1.views.py #分页:django分页:上一页、罗列所有页码、下一页,这种方式不适合数据比较多的情况, #我们需要自定义一个分页。 def index2(request): # for i in range(300): # name = 'root'+ str(i) # models.Use 阅读全文
posted @ 2020-04-20 16:08 梁劲雄 阅读(111) 评论(0) 推荐(0) 编辑
摘要: 1.views.py from app01 import pager def custom(request): #当前页码: current_page = request.GET.get('page') # 数据库总行数 all_count = models.UserInfo2.objects.al 阅读全文
posted @ 2020-04-20 15:48 梁劲雄 阅读(131) 评论(0) 推荐(0) 编辑
摘要: <! 母版 > <head> <!--替换css--> {% block css %}{% endblock %} </head> <body> <!--替换内容--> {% block content %}{% endblock %} <!--替换js--> {% block js %}{% en 阅读全文
posted @ 2020-04-13 15:28 梁劲雄 阅读(104) 评论(0) 推荐(0) 编辑
摘要: #cookie多用于登录和投票。 #1.cookie是浏览器里的键值对。 #2.cookie在请求头里面,每次向服务器发请求,都带着cookie过去。 #3.当登录成功,服务器给浏览器的cookie设置(添加)键值对,作为下一步访问服务器其他页面的凭证。 #4.服务器的每个页面都有对凭证的判断,当没 阅读全文
posted @ 2020-04-13 11:29 梁劲雄 阅读(167) 评论(0) 推荐(0) 编辑
摘要: import pymysql #把pymysql操作mysql的代码封装到类里面,可以实现一次连接,多次操作。 #前面代码是多次连接,多次操作,频繁连接会拖累操作数据库的速度。#一个self对象贯穿整个类,每一个方法里面都是同一个self对象。class Sqlhelper(): #实例化的时候,自 阅读全文
posted @ 2020-04-09 16:58 梁劲雄 阅读(301) 评论(0) 推荐(0) 编辑
摘要: 1.urls.py from django.contrib import admin from django.urls import path from app01 import views urlpatterns = [ path('add_model/', views.add_model), p 阅读全文
posted @ 2020-04-08 12:38 梁劲雄 阅读(647) 评论(0) 推荐(0) 编辑
摘要: 1.urls.py from django.contrib import admin from django.urls import path from app01 import views urlpatterns = [ path('admin/', admin.site.urls), path( 阅读全文
posted @ 2020-04-07 10:21 梁劲雄 阅读(366) 评论(0) 推荐(0) 编辑
摘要: 1、urls.py from django.contrib import adminfrom django.urls import pathfrom django.shortcuts import HttpResponse,render,redirectdef login(request): #第一 阅读全文
posted @ 2020-04-02 21:37 梁劲雄 阅读(230) 评论(0) 推荐(0) 编辑
摘要: 1、创建django项目之后,settings设置: 1.1 注释掉# 'django.middleware.csrf.CsrfViewMiddleware', 1.2 静态文件设置:添加static文件夹 STATIC_URL = '/static/' STATICFILES_DIRS = ( o 阅读全文
posted @ 2020-04-02 21:15 梁劲雄 阅读(218) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 ··· 12 下一页