pip3 install pillow #PIL
登陆图片验证(未实现局部刷新)
详细:https://www.cnblogs.com/qiangyuge/p/8025168.html
def get_color():
import random
return (random.randint(0,255),random.randint(0,255),random.randint(0,255))
def get_text(request):
import random
a=str(random.randint(0,9))
b=chr(random.randint(65,90))
c=chr(random.randint(97,122))
d=''
for i in range(5):
d+=random.choice([a,b,c])
request.session['code']=d
return d
def img_code(request):
if request.method=='GET':
from PIL import ImageDraw, Image,ImageFont
from io import BytesIO
img=Image.new('RGB',(320,30),color=get_color())
#画字
img_draw=ImageDraw.Draw(img)
font=ImageFont.truetype('static/aa.TTF',size=25)
img_draw.text((120,-5),get_text(request),get_color(),font=font,)
f = BytesIO ()
img.save (f, 'png')
data = f.getvalue ()
return HttpResponse(data) **********************************************************************************
def get_valid_code(request):
    # 第一种方式
    # with open('static/img/lhf.jpg','rb') as f:
    #     # 图片二进制
    #     data=f.read()
    # return HttpResponse(data)
    # 第二种方式:随机生成一张图片
    # pip3 install Pillow
    # pillow 是一个图形处理的模块,功能很强强大
    # 生成一张图片,第一个参数是模式:RGB,第二个参数是图片大小,第三个参数是图片颜色
    # img = Image.new('RGB', (320, 35), color=get_random_color())
    # # 保存到本地
    # with open('valid_code.png', 'wb') as f:
    #     # 直接用img的save方法,第一个参数是空文件,第二个参数图片格式
    #     img.save(f, 'png')
    # # 打开文件,再返回
    # with open('valid_code.png', 'rb') as f:
    #     data = f.read()
    # return HttpResponse(data)
    # 第三种方式
    # 在内存中生成一个空文件(把它想象成 open('valid_code.png', 'wb') as f:)
    # 一个是在硬盘上,一个是在内存中
    # img = Image.new('RGB', (320, 35), color=get_random_color())
    # f = BytesIO()
    # # 把图片保存到f中
    # # 放到内存中,存取比较快,而且有自动清理
    # img.save(f, 'png')
    #
    # data = f.getvalue()
    # return HttpResponse(data)
    # 第四种方式,在图片上写文字
    img = Image.new('RGB', (320, 35), color=get_random_color())
    # 拿到画笔,把图片传入画笔
    img_draw=ImageDraw.Draw(img)
    # 生成一个字体对象,第一个参数是字体文件的路径,第二个参数是字体大小
    font=ImageFont.truetype('static/font/ss.TTF',size=25)
    # 第一个参数,xy的坐标,第二个参数:要写的文字,第三个参数:写文字的颜色,第四个参数:字体
    # 不同的字体是不同的ttf文件
    img_draw.text((0,0),'python',get_random_color(),font=font)
    f = BytesIO()
    # 把图片保存到f中
    # 放到内存中,存取比较快,而且有自动清理
    img.save(f, 'png')
    data = f.getvalue()
    return HttpResponse(data)
表设计
  User 用户表
   -nid
   -name
   -password
   -email
   -phone
   -avatar   用户头像
   -create_date    用户注册时间
   -blog
  Blog  个人站点表
   -nid
   -title         标题
   -site_name     站点url名
   -theme     主题
  category: 文章分类表
   -nid
   -title  
   -blog   跟blog一对多
   
  tag:(文章关键字)
   -nid
   -title
   -blog    跟blog一对多
   
  article 文章表
   -nid
   -title
   -desc    摘要
   -create_time    auto_add_now:当该条记录创建时,自动添加当前时间
   -content   文章内容
   
   -category    一对多
   -tag         多对多
   -blog        一对多
   
  commit 评论表
   -nid
   -user     哪个用户
   -article  对哪篇文章
   -content   评论了什么内容
   -commit_time  时间
   
   -parent_id
   如何实现根评论与子评论?
    -有同学分析,要再建一张表,跟commit是一对多的关系(不好)
    
    -如何用这一个表,表示出根评论和子评论?
     -再加一个字段,标志,给那条评论,评论的
   
   
   
 nid user    article   content    parent_id
  
 1 1        1         111         null
 2   2        1         222         null
 3   3      1         333          1
 4   4   1         444          3
 5   3        1         反弹         4
  UpandDown 点赞表
   -nid
   -user     哪个用户
   -article  对哪篇文章
   -is_up   点赞还是点踩
   

												

随机推荐

  1. Spark SQL基本概念与基本用法

    1. Spark SQL概述 1.1 什么是Spark SQL Spark SQL是Spark用来处理结构化数据的一个模块,它提供了两个编程抽象分别叫做DataFrame和DataSet,它们用于作为 ...

  2. python matplotlib 库学习

    基本使用 import matplotlib.pyplot as plt import numpy as np x = np.linspace(-1,1,50) y = 2*x+1 plt.figur ...

  3. 理解BFC

    BFC:块格式化上下文(Block Formatting Context) 是Web页面的可视化CSS渲染的一部分,是布局过程中生成块级盒子的区域,也是浮动元素与其他元素的交互限定区域. BFC 是一 ...

  4. 052、overlay如何实现跨主机通信?(2019-03-19 周二)

    参考https://www.cnblogs.com/CloudMan6/p/7305989.html   今天开始学习 overlay 网络跨主机通信的原理   root@host01:~# ufw ...

  5. 10.tesseract

    1.Tesseract-OCR简介  一个Google支持的开源的OCR图文识别开源项目.支持多种语言(我使用的是3.02 版本,支持包括英文,简体中文,繁体中文),支持Windows,Linux,M ...

  6. getnameinfo函数

    一.函数原型 #include <netdb.h> int getnamefo(const struct sockaddr *sockaddr, socklen_t addrlen, ch ...

  7. 二十六、Linux 进程与信号---system 函数 和进程状态切换

    26.1 system 函数 26.1.1 函数说明 system(执行shell 命令)相关函数 fork,execve,waitpid,popen #include <stdlib.h> ...

  8. c#调用WebService实例

    在Winform中对数据库进行操作缺乏安全性,因而可以使用Winform调用WebService来实现对数据库的各种操作.在VS2010中,创建一个Web服务程序,第一:创建一个空的Web应用程序,名 ...

  9. 基础的POJ学习

    OJ上的一些水题(可用来练手和增加自信)(poj3299,poj2159,poj2739,poj1083,poj2262,poj1503,poj3006,poj2255,poj3094) 初期: 一. ...

  10. MySql数据库学习笔记(2)

    DELETE 语法:delete from 表名 [where condition] delete from grade; TRUNCATE 用于完全清空表数据,但表结构.索引.约束不变: 语法: t ...