require

28_django限制请求方法装饰器

£可爱£侵袭症+ 提交于 2019-11-30 12:08:04
Django限制请求方法 常见的请求有: GET/POST GET:GET请求一般用来向服务器索取数据,但不会向服务器提交数据,不会对服务器的状态进行更改 POST: POST请求一般是用来向服务器提交数据,会对服务器的状态进行更改 在Django中 限制请求方法的装饰器 Django 内置的视图装饰器可以给视图提供一些限制。比如这个视图只能通过 GET 的 method 访问 等。 from django.views.decorators.http import require_POST, require_http_methods, require_GET 1. reruire_http_methods from django.http.decorators.http import require_http_methods @require_http_methods(['GET']) # require_http_methods(['GET', 'POST']) def img_captcha(request, img_uuid): """ 生成图片验证码 url: /img_captcha/ :param request: :return: """ pass 2. require_GET @require_GET def check_username(request,

Why does require('underscore') return undefined when executed at the node.js REPL?

我只是一个虾纸丫 提交于 2019-11-30 11:46:53
When I run node in my console and type var _ = require('underscore'); , _ ends up undefined. If I put the same code in a file and execute it, the underscore library gets included as expected. $ node > var _ = require('underscore'); > console.log(_) undefined // underscore library does not load > var async = require('async'); undefined > console.log(async) // async library does { noConflict: [Function], nextTick: [Function], forEach: [Function], ... > But the same code in a .js file executed as node test.js shows both libraries loading as expected. What's going on? The Node repl binds _ to the

win7安装composer

无人久伴 提交于 2019-11-30 11:33:45
安装composer 1. 在Composer官网里下载 Composer-Setup.exe 2. 一键式安装,Settings Check选择php.exe的地址 Proxy Settings不需要填 验证composer 打开DOS窗口,输入composer,有下界面的图形则成功 使用composer 需要使用composer在项目下加入QueryList包 在项目目录下新建composer.json { "require": { "guzzlehttp/guzzle": "6.2.*", "jaeger/g-http": "^1.1", "monolog/monolog": "1.2.*", "jaeger/querylist": "^4.0", "jaeger/querylist-rule-baidu": "^4.0" } } 使用DOS进入到项目目录下,执行composer install,会出现vendor文件夹和composer.lock文件 如果已执行过composer install,需要新增QueryLlist则可以使用下边的方法 在composer.json里添加 "jaeger/querylist": "^4.0" 并执行composer update 或者直接执行 composer require jaeger/querylist 来源: oschina

In Node.js, am I creating a new object when “Require”?

可紊 提交于 2019-11-30 11:24:01
问题 So, what I'm not sure is that. if in ModuleA , I have: var mongoose = require('mongoose'); mongoose.connect(pathA); And in ModuleB , I have: var mongoose = require('mongoose'); mongoose.connect(pathB); And in the main program, I have: var mA = require('./moduleA.js'), mB = require('./moduleB.js'); So, when I run the main program, I guess I will create two mongoose "instances"; one connecting to pathA and one connecting to pathB, is that right? Also, in Module B, before I connect to pathB, is

Node.js - check if module is installed without actually requiring it [duplicate]

大憨熊 提交于 2019-11-30 11:18:32
问题 This question already has answers here : Check if a node.js module is available (5 answers) Closed 5 years ago . I need to check whether "mocha" is installed, before running it. I came up with the following code: try { var mocha = require("mocha"); } catch(e) { console.error(e.message); console.error("Mocha is probably not found. Try running `npm install mocha`."); process.exit(e.code); } I dont like the idea to catch an exception. Is there a better way? 回答1: You should use require.resolve()

深入解析Javascript异步编程

╄→гoц情女王★ 提交于 2019-11-30 11:06:24
这里深入探讨下Javascript的异步编程技术。(P.S. 本文较长,请准备好瓜子可乐 :D) 一. Javascript异步编程简介 至少在语言级别上,Javascript是单线程的,因此异步编程对其尤为重要。 拿nodejs来说,外壳是一层js语言,这是用户操作的层面,在这个层次上它是单线程运行的,也就是说我们不能像Java、Python这类语言在语言级别使用多线程能力。取而代之的是,nodejs编程中大量使用了异步编程技术,这是为了高效使用硬件,同时也可以不造成同步阻塞。不过nodejs在底层实现其实还是用了多线程技术,只是这一层用户对用户来说是透明的,nodejs帮我们做了几乎全部的管理工作,我们不用担心锁或者其他多线程编程会遇到的问题,只管写我们的异步代码就好。 二. Javascript异步编程方法 ES 6以前: * 回调函数 * 事件监听(事件发布/订阅) * Promise对象 ES 6: * Generator函数(协程coroutine) ES 7: * async和await PS:如要运行以下例子,请安装node v0.11以上版本,在命令行下使用 node [文件名.js] 的形式来运行,有部分代码需要开启特殊选项,会在具体例子里说明。 1.回调函数 回调函数在Javascript中非常常见,一般是需要在一个耗时操作之后执行某个操作时可以使用回调函数。

Is require File.expand_path(…, __FILE__) the best practice?

会有一股神秘感。 提交于 2019-11-30 10:26:39
问题 Is require File.expand_path(..., __FILE__) the best way to require other files within a project? 回答1: In Ruby 1.9.2 + require_relative is probably the more correct way to do it. require was changed to not include your '.' directory for security reasons. require_relative was added to provide a local-file solution for modules relative to your calling script's path. You can search here on StackOverflow, particularly in "What is require_relative in Ruby?", and the internets and find usage tricks

透彻掌握Promise的使用

瘦欲@ 提交于 2019-11-30 10:16:22
透彻掌握Promise的使用 Promise的重要性我认为我没有必要多讲,概括起来说就是必须得掌握,而且还要掌握透彻。这篇文章的开头,主要跟大家分析一下,为什么会有Promise出现。 在实际的使用当中,有非常多的应用场景我们不能立即知道应该如何继续往下执行。最重要也是最主要的一个场景就是ajax请求。通俗来说,由于网速的不同,可能你得到返回值的时间也是不同的,这个时候我们就需要等待,结果出来了之后才知道怎么样继续下去。 // 简单的ajax原生实现 var url = 'https://hq.tigerbrokers.com/fundamental/finance_calendar/getType/2017-02-26/2017-06-10'; var result; var XHR = new XMLHttpRequest(); XHR.open('GET', url, true); XHR.send(); XHR.onreadystatechange = function() { if (XHR.readyState == 4 && XHR.status == 200) { result = XHR.response; console.log(result); } } 在ajax的原生实现中,利用了onreadystatechange事件,当该事件触发并且符合一定条件时

【深入浅出Node.js系列十一】Node.js开发框架Express4.x

久未见 提交于 2019-11-30 09:16:34
#0 系列目录# 深入浅出Node.js系列 【深入浅出Node.js系列一】什么是Node.js 【深入浅出Node.js系列二】Node.js&NPM的安装与配置 【深入浅出Node.js系列三】深入Node.js的模块机制 【深入浅出Node.js系列四】Node.js的事件机制 【深入浅出Node.js系列五】初探Node.js的异步I/O实现 【深入浅出Node.js系列六】Buffer那些事儿 【深入浅出Node.js系列七】Connect模块解析 【深入浅出Node.js系列八】一个基于Node.js完整的Web应用实战 【深入浅出Node.js系列九】一起撸Node.js 【深入浅出Node.js系列十】一个简单的静态文件合并服务器 【深入浅出Node.js系列十一】Node.js开发框架Express4.x #1 建立项目# 让我们从头开始Express4.x的安装和使用吧,安装Node和NPM在本文就不多说了。Linux环境安装请参考文章, Node.js&NPM的安装与配置 ,Window环境安装直接下载Node的安装文件,双击安装就行了。 首先,我们需要安装express库 。在Express3.6.x之前的版本,Express需要全局安装的,项目构建器模块是合并在Express项目中的,后来这个构建器被拆分出来,独立成为了一个项目express

nodejs链接mysql集群

三世轮回 提交于 2019-11-30 07:58:48
const mysql = require('mysql2'); const config = require('../config/config'); module.exports = async (sql, options) => { const poolCluster = mysql.createPoolCluster({ removeNodeErrorCount: 1, // Remove the node immediately when connection fails. defaultSelector: 'RR' //RR,RANDOM,ORDER }); poolCluster.add('node1', config.mysql.node1); poolCluster.add('node2', config.mysql.node2); poolCluster.add('node3', config.mysql.node3); poolCluster.add('node4', config.mysql.node4); return new Promise((resolve, reject) => { poolCluster.getConnection((err, conn) => { if (err) { reject(err) } else { conn.query