momo's Blog.

momo's Blog.

大佬带带我啊!我很好带的。

django前后端分离的一些问题及解决方案
前言django 前后端分离时,会遇到很多问题,再次罗列一下,省的采坑. 解决跨域问题前后端分离,首先解决的问题就是跨域问题. 我们需要安装用于解决跨域的插件 1python -m pip install django-cors-headers 在setting 中添加如下配置 123456789101112# 将corsheaders添加为我们的django appINSTALLED_APPS += ( 'corsheaders',)# 添加自定义中间件注意中间件顺序, 跨域的中间件尽量放置在前MIDDLEWARE += ( 'corsheaders.middlew...
WebSSH功能简单实现
前言前几天学习了django-channels如何基于ws建立聊天室, 针对于ws在运维方面实际用途还是很多的.今天基于ws,做一个webssh的小案例用到的新模块 Paramiko xtermjs Django Channel 使用WebSSH操控远程服务器在学习之前,需要简单了解一下paramiko的基本使用 1234567891011# 实例化SSHclientself.ssh = paramiko.SSHClient()#当远程服务器没有添加本地host秘钥时,将自动添加.无需使用yes or noself.ssh.set_missing_host_key_policy(pa...
django-rest-framework使用
前言记录一下django-rest-framework使用,方便自己查询 安装使用pip安装 针对python版本以及django版本要求 Python (3.5, 3.6, 3.7, 3.8) Django (2.2, 3.0)1pip install djangorestframework 添加rest_framework应用到 INSTALLED_APPS 配置中 1234INSTALLED_APPS = [ ... 'rest_framework',] 定义Serializers 序列化器添加模型类我们在应用下添加一个模型类 123456from djang...
logstash发送速率太低检查
前言线上环境的logstash发送速率一直太低,而且性能使用也异常的低。上次测试,每天日志量500G+,延迟有2小时左右。此次正好抽空去测试一下什么原因导致的此问题。 环境说明 服务 配置 数量 logstash 8c8g 1 elasticsearch 8c 16g 1 filebeat 4c4g 1 logstash配置 123456789101112http.host: "0.0.0.0"xpack.monitoring.enabled: truexpack.monitoring.elasticsearch.hosts: [ "http://10.10.140...
Python Channels库使用

前言

记录一下django channels 库的基本使用
本文档记录 官方文档教程,可直接参考官方文档: 教程第一部分

基本设置

创建聊天室应用

代码结构如下图

添加我们的chatroom应用. 编辑djangoProject/settings.py文件, 在列表中加入我们的APP名称

1
2
3
4
5
6
7
8
9
10
11
# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'chatroom'
]

添加索引视图

在应用下下建立一个templates/chatroom/index.html 文件。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<!-- chatroom/templates/chatroom/index.html -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Chat Rooms</title>
</head>
<body>
What chat room would you like to enter?<br>
<input id="room-name-input" type="text" size="100"><br>
<input id="room-name-submit" type="button" value="Enter">

<script>
document.querySelector('#room-name-input').focus();
document.querySelector('#room-name-input').onkeyup = function(e) {
if (e.keyCode === 13) { // enter, return
document.querySelector('#room-name-submit').click();
}
};

document.querySelector('#room-name-submit').onclick = function(e) {
var roomName = document.querySelector('#room-name-input').value;
window.location.pathname = '/chat/' + roomName + '/';
};
</script>
</body>
</html>
Windwos下安装python-ansible报错

1. 前言

windows 下通过 pip install 的方式安装 ansible 会报错

1
2
ERROR: Could not install packages due to an EnvironmentError: [WinError 206] 文件名或扩展名太长。: 'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\pip-req-build-7a94xirm\\test/integration/t
argets/copy/files/subdir/subdir1/circles/subdir1/circles/subdir1/circles/subdir1/circles/subdir1/circles/subdir1/circles/subdir1/circles/subdir1/circles/subdir2/subdir3/subdir4/'
PromQL Notes
理解时间序列数据类型 即时向量(Instant vector) 范围向量(Range vector) 标量(Scalar) 字符串(String) 文字字符串文字在单引号,
axios基本用法

1. axios 基本特性

axios 官网: https://github.com/axios/axios

1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
axios.delete('http://localhost:8000/depart/3', {
params: {
id: 2
}
}).then(function (ret){
// data熟悉是固定的写法,用于获取后台的实际数据
console.log(ret.data)
})

axios.put('http://localhost:8000/depart/3', {
params: {
id: 2
}
}).then(function (ret){
// data熟悉是固定的写法,用于获取后台的实际数据
console.log(ret.data)
})

axios.get('http://localhost:8000/depart/').then(function (ret){
// data熟悉是固定的写法,用于获取后台的实际数据
console.log(ret.data)
})
Promise基本用法

1. Promise 基本用法

  • 实例化 Promise 对象, 构造函数中传递函数,该函数中用于处理异步任务
  • 通过 resolvereject 两个参数用于处理成功和失败的两种情况,并通过 .then 获取处理结果
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
const p = new Promise(function (resolve, reject){
// 这里用于实现异步任务
setTimeout(function (){
let flag = true
if(flag){
resolve('hello')
}else {
reject('错错了')
}
}, 1000)
})
p.then(function (data){
console.log(data)
},function (info){
console.log(info)
})
avatar
Momo
不专业的运维工程师
FRIENDS
Baidu Google