Pease帮助在django 1.11中使用csrf标记
在view.py我使用以下代码:
from django.shortcuts import render_to_response, redirect
from django.contrib import auth
from django.views.decorators.csrf import csrf
def login(request):
args = {}
args.update(csrf(request))
if request.POST:
username = request.POST.get('username', '')
password = request.POST.get('password', '')
user = auth.authenticate(username=username, password=password)
if user is not None:
auth.login(request, user)
return redirect('/')
else:
args['login_error'] = '???????????? ?? ??????';
return render_to_response('login.html', args)
else:
return render_to_response('login.html', args)
Run Code Online (Sandbox Code Playgroud)
但控制台显示按照错误消息:
文件"/home/kalinin/django/login/views.py",第3行,来自django.views.decorators.csrf import csrf ImportError:无法导入名称'csrf'
在django 1.8我使用类似的代码,但导入csrf:
from django.core.context_processors import csrf
Run Code Online (Sandbox Code Playgroud)
和应用程序运行没有问题
请帮助运行我的django 1.11应用程序
我有字符串"513".我需要数组["5","1","3"].我的解决方案:
function nextBigger(num){
let numStr = '' + num;
let numArr = [];
for(let i = 0; i < numStr.length; ++i) {
numArr.push(numStr[i]);
}
console.log(numArr);
}
nextBigger(513);
Run Code Online (Sandbox Code Playgroud)
但是这个解决方案很大且多余.我需要更短的解决方案
请帮我把我的2个阵列asc排序和desc排序.我的解决方案没有奏效
function solve(arr){
var descArr = [];
var ascArr = [];
ascArr = arr.sort(function(a, b) {
return a - b;
});
descArr = arr.sort(function(a, b) {
return b - a;
});
console.log(descArr);
console.log(ascArr);
};
solve([15,11,10,7,12])
Run Code Online (Sandbox Code Playgroud)
Console.log显示类似的排序数组.