路飞_day2
settings配置:
python:
django 2x : path () --> 没有正则
re_path() --> 支持正则
django 1x : url () --> 匹配正则
drf框架的配置:
REST_FRAMEWORK = {}
1.异常模块
'EXCEPTION_HANDLER': 'utils.exception.exception_handler',
2.三大认证
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
],
# 拥有具体权限限制的视图类局部配置权限
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.AllowAny',
],
# 拥有具体频率限制的视图类局部配置频率
'DEFAULT_THROTTLE_CLASSES': [],
# 频率限制scope的规则
'DEFAULT_THROTTLE_RATES': {
'sms': '1/min'
},
drf-jwt配置:签发 | 刷新 | 限制 --》 token
import datetime
JWT_AUTH = {
'JWT_EXPIRATION_DELTA': datetime.timedelta(days=1),
'JWT_ALLOW_REFRESH': False,
'JWT_REFRESH_EXPIRATION_DELTA': datetime.timedelta(days=7),
}
django 缓存
request.query_params.get() get请求携带的参数
request.data.get() post 请求携带的参数
re.match(r'') re正则匹配
r'^1[3-9][0-9]{9}$' 匹配手机号
django 缓存:
cache.get(key,value,exp) exp: 时间限制
set(key,value,exp) 创建
remove(key,value,exp) 使之失效
# 验证码校验通过,验证码失效(验证码一次性使用)
cache.set(settings.SMS_CACHE_FORMAT % mobile, None, 0)
问题:
问题: app 内corsheaders 模块???
问题: django框架内中简介 corsheaders.middleware.CorsMiddleware 会变黄
--》 跨域设置 (允许访问的方法)
问题: 返回异常信息要携带 http_status= ???
问题: 序列化配置中 添加 update | create
create方法是是需要重写:默认入库,密码是明文
: 密文存储
vue.config.js
jquery 配置:
const webpack = require("webpack");
module.exports = {
configureWebpack: {
plugins: [
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery",
"window.$": "jquery",
Popper: ["popper.js", "default"]
})
]
}
};
cookies 使用:
cnpm install
# main.js
// cookies 配置 (只能前端使用)
import cookies from 'vue-cookies'
Vue.prototype.$cookies = cookies;
/* 在组件逻辑中使用
this.$cookies.set(key, value, exp) // exp: '1s' | '1h' | '1d'
this.$cookies.get(key)
this.$cookies.remove(key)
this.token = this.$cookies.get('token') || '';
this.username = this.$cookies.get('username') || '';
前端页面 小组件之间的转换:
小组件 在大组件内完成配置
<Login v-if="is_login" @close="close_login" @go="pull_register" @success="login_success" />
<Register v-if="is_register" @close="close_register" @go="pull_login" @success="register_success" />
注册:
<script>
import Login from './Login'
import Register from "./Register";
export default {
name: "Header",
components:{
Login,
Register
},
小组件--》大组件:
自定义事件: this.$emit('事件')
页面配置:
.banner img {
height: 400px;
/* 设置一个默认的长度 进行页面居中展示 */
margin-left: calc(50% - 1920px / 2);
}
.el-carousel__item {
/* 设置默认值*/
min- 1200px;
}
// 避免页面出现屏幕不足,横向产生滚动条 *
body {
overflow: hidden;
}
登录模态框设计:
// 显示登录模态框
pull_login() {
this.is_login = true;
this.close_register();
},
close_login() {
this.is_login = false;
},
pull_register() {
this.is_register = true;
this.close_login();
},
close_register() {
this.is_register = false;
},
login_success() {
this.close_login();
this.token = this.$cookies.get('token') || '';
this.username = this.$cookies.get('username') || '';
},
register_success() {
this.pull_login();
},
logout() {
this.$cookies.remove('token');
this.$cookies.remove('username');
this.token = '';
this.username = '';
}
},
created() {
sessionStorage.url_path = this.$route.path;
this.url_path = this.$route.path;
// 也可以在data中只做空声明,钩子中初始化
// this.token = this.$cookies.get('token') || '';
// this.username = this.$cookies.get('username') || '';
}
登录框设计:
<div class="login">
<div class="box">
<i class="el-icon-close" @click="close_login"></i>
<div class="content">
<div class="nav">
<span :class="{active: login_method === 'is_pwd'}"
@click="change_login_method('is_pwd')">密码登录</span>
<span :class="{active: login_method === 'is_sms'}"
@click="change_login_method('is_sms')">短信登录</span>
</div>
<el-form v-if="login_method === 'is_pwd'">
<el-input
placeholder="用户名/手机号/邮箱"
prefix-icon="el-icon-user"
v-model="username"
clearable>
</el-input>
<el-input
placeholder="密码"
prefix-icon="el-icon-key"
v-model="password"
clearable
show-password>
</el-input>
<el-button type="primary" @click="login">登录</el-button>
</el-form>
<el-form v-if="login_method === 'is_sms'">
<el-input
placeholder="手机号"
prefix-icon="el-icon-phone-outline"
v-model="mobile"
clearable
@blur="check_mobile">
</el-input>
<el-input
placeholder="验证码"
prefix-icon="el-icon-chat-line-round"
v-model="sms"
clearable>
<template slot="append">
<span class="sms" @click="send_sms">{{ sms_interval }}</span>
</template>
</el-input>
<el-button type="primary" @click="login_mobile">登录</el-button>
</el-form>
<div class="foot">
<span @click="go_register">立即注册</span>
</div>
</div>
</div>
</div>