zoukankan      html  css  js  c++  java
  • BBS第一天

    需求分析:

    1,注册:前后台校验,ajax注册,选取图形,图形上传

    2,登录:ajax登录,图形验证码

    3.博客首页

    4.个人站点

    5.文章的点赞与点踩

    6.评论:根评论,子评论

    7.后台管理

    8.发布博客:防止xss攻击

    数据库设计

    用户表:User

    username:账号

    password:密码

    data_joined:注册时间

    avatar:图像

    telephone:电话

    blog:博客站点(一对一)

    博客站点表:Blog

    name:站点名

    title:标题

    theme:站点主体样式

    category:拥有的分类(多对多)

    tag:拥有的标签(多对多)

    分类表:Category

    name:分类名

    标签表:Tag

    name:标签名

    文章表:Article

    title:文章标题

    desc:文章摘要

    content:文章内容

    create_time:发布时间

    blog:所属博客站点(一对多)

    category:所属分类(一对多)

    tag:拥有的标签(多对多)

    点赞点踩表:UpOrDown

    user:点踩点赞用户(一对多)

    article:点赞点踩文章(一对多)

    is_up:点踩或点赞

    评论表:Common

    user:评论者(一对多)

    article:评论文章(一对多)

    content:评论内容

    parent:父评论(自关联)

    接口规则

    状态码:

    SUCCESS('0000','查询成功')

    NODATA('0001','查询成功无记录'),

    FAILED('0002','查询失败')

    ACCOUNT_ERROR('1000','账户不存在或被禁用')

    API_NOT_EXISTS('1001','请求的接口不存在')

    API_NOT_PER('1002','没有该接口的访问权限')

    PARAMS_ERROR('1004','参数为空或格式错误')

    SIGN_ERROR('1005','数据签名错误')

    UNKNOWN_IP('1099','非法IP请求')

    SYSTEM_ERROR('9999','系统异常')

    规范制定:

    {

    'status':0,

    'msg':'ok',

    'data':{}

    }

    相关配置

    DATABASES = {
    'default': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': 'bbs',
    'HOST': '127.0.0.1',
    'USER': 'root',
    'PASSWORD': 'root'
    }
    }
    AUTH_USER_MODEL = 'blog.User'

    STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static')
    ]

    import pymysql
    pymysql.install_as_MySQLdb()

    1.Auth模块:用户登录认证

    操作user表与session表

    from django.contrib.auth.models import User,AbstractUser

    user = User.objects.create_user()

    user.set_password()

    user.save()

    user.check_password()

    class MyUser(AbstractUser):

      info=models.CharField()

    settings.py

    AUTH_USER_MODEL = app_name.MyUser

    from django.contrib.auth import authenticate,login,logout

    authenticate(username="",password="")

    login(request,user)

    logout(request)

    方法:request.user.is_authenticated

    from django.contrib.auth.decorators import login_required

    @login_required(login_url="")

    2.forms模块:form表单验证与渲染

    class CheckFrom(forms.Form):
    username = forms.CharField(
    min_length=3,
    error_messages={
    'min_length': '最少3',
    'required': '必填项',
    },
    label="用户名",
    widget=forms.PasswordInput(attrs={
    'class': 'password',
    'placeholder': '请输入密码'
    })
    )
    def clean_username(self):
    cleaned_username = self.cleaned_data.get('username')
    from django.core.exceptions import ValidationError
    pass # 如果出错,抛异常 raise ValidationError => key: username

    return cleaned_username
    def clean(self):
    # 可以获取多个字段,完成多个字段的二次校验
    pass # 如果出错,抛异常 raise ValidationError => key:__all__


    check_form = CheckFrom({})
    check_form.is_valid() # 做系统校验

    # 类的属性的方法
    # check_form.is_valid()
    # check_form.cleaned_data
    # check_form.errors
    # 在DTL中使用
    # check_form.username # 选择字段
    # check_form.username.errors.0 # 渲染具体字段的错误信息

    # all_error = check_form.errors.get('__all__')
    # all_error.0
    # check_form.username.label
    # check_form.username.html_name # 字段名
    # check_form.username.auto_id # id_字段名

  • 相关阅读:
    在循环中禁止remove/add
    [算法竞赛入门]WERTYU
    [算法竞赛入门]Tex Quotes
    [算法竞赛入门]竖式问题
    [算法竞赛入门]蛇形填数
    [C++面试]关于const的使用方法
    [C++面试]单例模式-设计模式
    [C++面试]C++的三种继承(public/protected/private继承)
    用微服务架构,有哪些好处?
    东软数据可视化分析, 已经方便成这样?!
  • 原文地址:https://www.cnblogs.com/suncunxu/p/10531853.html
Copyright © 2011-2022 走看看