小编bfi*_*ssa的帖子

Django Form request.POST.get()始终返回空

对不起,如果这是一个菜鸟问题.我正在为Django应用程序创建一个登录表单,但是我无法让它运行起来.request.POST.get()不返回任何内容,因此身份验证始终失败.我错过了一些明显的东西吗

的login.html:

{% extends "base.html" %}

{% block content%}

<h2>Welcome! Please login to continue.</h2> <br>
<form action="{% url 'account:authenticate' %}" method="post">
    {% csrf_token %}
    <div >
        <label for='username'> Username: </label>
        <input type='text' name='Username' id='username'> <br><br>
        <label for='password'>Password:  </label>
        <input type='password' name='Password' id='password'><br><br>
        <input type='submit' value='Login'>
    </div>
</form>
Run Code Online (Sandbox Code Playgroud)

views.py的相关部分:

from django.shortcuts import render, get_object_or_404
from datetime import datetime   
from django.http import HttpResponse, Http404, HttpResponseRedirect
from django.template import loader
from random import randrange
from django.contrib.auth import authenticate

def login(request):
    return render (request, …
Run Code Online (Sandbox Code Playgroud)

python django

6
推荐指数
1
解决办法
5680
查看次数

如何使用无服务器框架通过AWS API网关返回用Node.js编写的AWS Lambda函数的错误?

我正在编写供内部使用的API,并且这是我第一次使用无服务器框架。我正在Node.js中编写Lambda函数,并使用AWS API Gateway进行连接。

在某些情况下,我想返回一个自定义错误消息,而我试图编写一个允许我执行此操作的函数。现在,每当Lambda进程失败时,我都会从API收到一条标准消息。在代码中,如果我尝试使用杀死进程process.exit(1),即使我已经使用callback()以下命令返回了错误,也会收到一般错误:

{
    "message": "Internal server error"
}
Run Code Online (Sandbox Code Playgroud)

如果不使用process.exit(1),我会callback()在日志中看到通过错误返回的错误,但是该过程继续进行,最终超时:

{
    "message": "Endpoint request timed out"
}
Run Code Online (Sandbox Code Playgroud)

我已经尝试了几种使用该callback()方法返回错误的方法,但是到目前为止,我还没有成功。我试过这种方法:

async function return_error(callback, context, error, returnCode){
  console.error("FATAL ERROR: ", error);
  let ErrorObj = {
    errorType : "InternalServerError",
    httpStatus : 500,
    requestId : context.awsRequestId,
    errorMessage : error
}
  callback(JSON.stringify(ErrorObj));
  process.exit(1);
}
Run Code Online (Sandbox Code Playgroud)

还有这个:

async function return_error(callback, error, returnCode){
  console.error("FATAL ERROR: ", error);
  callback({
    isBase64Encoded: false,
    statusCode: returnCode,
    headers: { 'Content-Type': 'application/json' …
Run Code Online (Sandbox Code Playgroud)

node.js aws-lambda aws-api-gateway serverless-framework serverless

1
推荐指数
1
解决办法
3499
查看次数