optional

Django开发文档-域用户集成登录

旧巷老猫 提交于 2020-04-24 02:00:55
项目概述: 一般在企业中,用户以WINDOWS的域用户统一的管理,所以以Django快速开发的应用,不得不集成AD域登录。 网上一般采用django-python3-ldap的库来做集成登录,但是本方案中需要同时使用域用户登录以及站点用户登录的功能。所以我们直接改写django的ModelBackend类以及User类来实现。 实现功能 : User表中增加一个 是否是域用户的字段,如果登录用户是域用户则采用ldap认证,如果不是域用户还采用Django本身的验证。 实现分析: 一、User表中如何增加字段 Django的auth_user表的字段是由django.contrib.auth.models中的User类控制的。 # Django源码 class User(AbstractUser): """ Users within the Django authentication system are represented by this model. Username and password are required. Other fields are optional. """ class Meta(AbstractUser.Meta): swappable = ' AUTH_USER_MODEL ' 我们需要对User类进行改写来实现增加字段的功能 步骤一

Django开发文档-域用户集成登录

♀尐吖头ヾ 提交于 2020-04-23 23:02:01
项目概述: 一般在企业中,用户以WINDOWS的域用户统一的管理,所以以Django快速开发的应用,不得不集成AD域登录。 网上一般采用django-python3-ldap的库来做集成登录,但是本方案中需要同时使用域用户登录以及站点用户登录的功能。所以我们直接改写django的ModelBackend类以及User类来实现。 实现功能 : User表中增加一个 是否是域用户的字段,如果登录用户是域用户则采用ldap认证,如果不是域用户还采用Django本身的验证。 实现分析: 一、User表中如何增加字段 Django的auth_user表的字段是由django.contrib.auth.models中的User类控制的。 # Django源码 class User(AbstractUser): """ Users within the Django authentication system are represented by this model. Username and password are required. Other fields are optional. """ class Meta(AbstractUser.Meta): swappable = ' AUTH_USER_MODEL ' 我们需要对User类进行改写来实现增加字段的功能 步骤一

漫画:工作这么多年,你居然不知道 Maven 中 Optional 和 Exclusions 的区别?

梦想与她 提交于 2020-04-23 22:31:34
Maven 依赖排除(Exclusions) 因为 Maven 构建项目具有依赖可传递的特性,当你在 pom.xml 添加某个依赖时,可能也会引入不需要的依赖到你的项目中,这将会会可能引起如下问题: Jar 包版本冲突,如老版本 Jar 包缺失某个方法; JDK 版本不兼容; 老版本存在安全漏洞; ... 为了解决这些问题,Maven 容许你通过 <exclusions> 来排除你不想要的依赖。这样,在你构建项目时,这些被排除依赖,将不会被打包进你的项目中。 PS: <exclusions> 需要在具体的依赖上显示指定,针对特定的 groupId 和 artifactId 。 如何使用呢? 在 <dependency> 节点中添加 <exclusions> ,指定你想要排除的依赖,如下所示: <project> ... <dependencies> <dependency> <groupId>sample.ProjectA</groupId> <artifactId>Project-A</artifactId> <version>1.0</version> <scope>compile</scope> <exclusions> <exclusion> <!-- 在这里声明,将项目A中的项目B依赖排除 --> <groupId>sample.ProjectB</groupId>

npm WARN deprecated fsevents windows

只谈情不闲聊 提交于 2020-04-23 08:29:53
更新下 使用 yarn 貌似会帮助跳过这个问题: info fsevents@2.1.2: The platform "win32" is incompatible with this module. info "fsevents@2.1.2" is an optional dependency and failed compatibility check. Excluding it from installation. info fsevents@1.2.9: The platform "win32" is incompatible with this module. info "fsevents@1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation. === 有需要下载了一个模板项目,安装ui部分失败,提示: npm WARN deprecated fsevents@1.2.9: One of your dependencies needs to upgrade to fsevents v2: 1) Proper nodejs v10+ support 2) No more fetch ing binaries from AWS,

解决npm ERR!Unexpected end of JSON input while paring near (解析附近时JSON输入意外结束)'...."^2.0.0-r...

让人想犯罪 __ 提交于 2020-04-23 08:28:42
摘要    最近更新了一次node,但是更新后npm的命令总是会报 npm WARN deprecated fsevents@2.0.6: Please update: there are crash fixes npm WARN deprecated text-encoding@0.7.0: no longer maintained npm WARN deprecated fsevents@1.2.9: One of your dependencies needs to upgrade to fsevents v2: 1) Proper nodejs v10+ support 2) No more fetching binaries from AWS, smaller package size npm WARN deprecated core-js@2.3.0: core-js@<3.0 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3. npm WARN deprecated core-js@1.2.7: core-js@<2

JDK1.8中的try-with-resources声明

泪湿孤枕 提交于 2020-04-23 05:01:06
转载自:http://www.importnew.com/26144.html 虽然我们开始了Java8的旅程,但是很多人直接从java6上手了java8, 也许有一些JDK7的特性你还不知道,在本章节中带你回顾一下我们忘记了的那些特性。 尽管我们不能讲所有特性都讲一遍,挑出常用的核心特性拎出来一起学习。 异常改进 try-with-resources 这个特性是在JDK7种出现的,我们在之前操作一个流对象的时候大概是这样的: 1 2 3 4 5 6 7 8 9 10 11 12 try { // 使用流对象 stream.read(); stream.write(); } catch (Exception e){ // 处理异常 } finally { // 关闭流资源 if (stream != null ){ stream.close(); } } 这样无疑有些繁琐,而且finally块还有可能抛出异常。在JDK7种提出了try-with-resources机制, 它规定你操作的类只要是实现了AutoCloseable接口就可以在try语句块退出的时候自动调用close 方法关闭流资源。 1 2 3 4 5 6 public static void tryWithResources() throws IOException { try ( InputStream ins =

浅谈requests库

*爱你&永不变心* 提交于 2020-04-21 05:03:33
本文为 博客园ShyButHandsome 的原创作品,转载请注明 出处 右边有目录,方便快速浏览 安装 pip install requests # 是requests而不是request(有s的) requests的简单使用 # requests的简单使用,看看效果就行,后面会更仔细细讲 import requests r = requests.get("https://www.baidu.com") # 构造一个Request对象, 返回一个Response对象 print(r.status_code) # 查看状态码,检查是否成功,200则为成功 print(r.encoding) # 查看当前编码,默认为header的charset字段 print(r.apparent_encoding) # 查看requests根据上下文判断的编码(备选编码) r.encoding = 'utf-8' #此处我们是已知网页编码才这么写 # 一般来说,我们都是采取r.encoding = r.apparent_encoding 的方式让它自己转换编码 print(r.text) # 查看获取到的网页内容 简单拓展:(后续会更加详细的讲) 方法 说明 HTML requests.request() 构造一个请求,支撑以下各方法的基础方法 \(ALL\) requests.get() 获取

asp.net core 系列之Configuration

夙愿已清 提交于 2020-04-20 10:05:22
在 ASP.NET Core 中的 App configuration 是通过 configuration providers 基于 key-value 对建立的。 Configuration providers 读取配置文件到 key-value ,从多种 配置源 中: Azure key Vault Command-line arguments Custom providers(installed or created) Directory files Environment variables In-memory .NET objects Setting files 用于提供 Configuration 配置的包是包含在 Microsoft.AspNetCore.App metapackage 里。下面的代码示例,将会使用 Microsoft.Extensions.Configuration 命名空间。 using Microsoft.Extensions.Configuration; 一.概述 1.Host vs App configuration(对比) 在应用配置和启动之前, host 被配置和 launched( 发动,开展 ) 。 Host 负责应用的 startup 和生命周期管理。应用和主机都是用这个主题描述的 configuration providers

与Bootstrap 3垂直对齐

筅森魡賤 提交于 2020-04-19 06:29:35
问题: I'm using Twitter Bootstrap 3, and I have problems when I want to align vertically two div , for example — JSFiddle link : 我正在使用Twitter Bootstrap 3,并且在要垂直对齐两个 div 时遇到问题,例如 -JSFiddle链接 : <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"> <!-- Optional theme --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css"> <!-- Latest compiled and minified JavaScript --> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"><

.Net Core结合AspNetCoreRateLimit实现限流

六眼飞鱼酱① 提交于 2020-04-18 17:36:13
前言   相信使用过 WebApiThrottle 的童鞋对AspNetCoreRateLimit应该不陌生, AspNetCoreRateLimit 是一个ASP.NET Core速率限制的解决方案,旨在控制客户端根据IP地址或客户端ID向Web API或MVC应用发出的请求的速率。AspNetCoreRateLimit包含一个 IpRateLimitMiddleware 和 ClientRateLimitMiddleware ,每个中间件可以根据不同的场景配置限制允许IP或客户端,自定义这些限制策略,也可以将限制策略应用在每​​个API URL或具体的HTTP Method上。 实践   起初是因为新做的项目中,有天查询日志发现,对外的几个公共接口经常被“恶意”调用,考虑到接口安全性问题,增加限流策略。    AspNetCoreRateLimit GayHub: https://github.com/stefanprodan/AspNetCoreRateLimit 根据IP进行限流   通过nuget安装AspNetCoreRateLimit,当前版本是3.0.5,因为实际项目中用的都是分布式缓存,在这里不用内存存储,而是 结合Redis进行使用 ,内存存储直接参考官方的Wiki就可以了。 Install-Package AspNetCoreRateLimit Install