小编Abh*_*mar的帖子

如何在 django Rest 框架中使用仅 http 的 cookie?

我读到了一些与在本地存储中存储 jwt 令牌相关的问题,这就是我尝试将令牌存储在仅 http cookie 中的原因。我正在使用以下方法。

from rest_framework.views import APIView
from rest_framework.response import Response
import jwt
from django.conf import settings
from rest_framework import status

class LoginView(APIView):
    def post(self, request, format=None):
        email = request.data['email']
        password = request.data['password']

        # dummy user authentication
        if email == 'email' and password == 'password':
            encoded = jwt.encode(
                {'email': email}, settings.SECRET_KEY, algorithm='HS256')

            response = Response()
            response.set_cookie(key='token', value=encoded, httponly=True)
            response.data = {
                'user': email,
            }
            return response
        else:
            return Response({'error': 'wrong credentials'}, status=status.HTTP_401_UNAUTHORIZED)

Run Code Online (Sandbox Code Playgroud)

问题 1:这是使用 django Rest 框架设置 …

python authentication django cookie-httponly django-rest-framework

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

当我编译 .c 文件时,它总是创建名为“a”的 .exe 文件

我使用GCC编译器在CMD上编译并运行C程序。当我使用命令编译 C 程序时,gcc hello.c它会创建一个名为 file 的可执行文件a.exe,但当我使用 IDE 时,它使用与 .c 文件相同的名称hello.exe。是否可以在CMD上创建与.c文件名相同的.exe文件?

c gcc

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

谁是C和C++的所有者?

我只是想知道谁是CC++的所有者,比如OracleJava的所有者,他们发布了新版本的Java.那么谁可以为C和C++提供更新.

c c++

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

为什么需要 int 类型来处理 EOF 和 getchar() 的返回?

正如书中所写——

问题在于区分输入的结尾和有效数据。解决方案是,当没有更多输入时,getchar 返回一个独特的值,该值不能与任何实际字符混淆。该值称为 EOF,即“文件结束”。我们必须将 c 声明为一个足够大的类型,以容纳 getchar 返回的任何值。我们不能使用 char,因为除了任何可能的 char 之外,c 还必须足够大才能容纳 EOF。因此我们使用 int。

main()
{
    int c;
    c = getchar();
    while(c != EOF) {
    putchar(c);
    c = getchar();
    }
}
Run Code Online (Sandbox Code Playgroud)

我无法理解使用 int 而不是 char 的实际原因。EOF 将返回无法存储在 char 中的内容。

c getchar

-3
推荐指数
1
解决办法
825
查看次数