小编Roh*_*mar的帖子

"detail": "方法 \"GET\" 不允许。" Django 休息框架

我知道这个问题可能是重复的,但我尝试了很多解决方案,但无法理解。我完全按照本教程进行操作,但在“用户列表”页面上出现此错误。其他一切都很好。有人可以指出错误是什么吗?

class UserList(APIView):
"""
Create a new user. It's called 'UserList' because normally we'd have a get
method here too, for retrieving a list of all User objects.
"""

permission_classes = (permissions.AllowAny,)
http_method_names = ['get', 'head']

def post (self, request, format=None):
    self.http_method_names.append("GET")

    serializer = UserSerializerWithToken(data=request.data)
    if serializer.is_valid():
        serializer.save()
        return Response(serializer.data, status=status.HTTP_201_CREATED)
    return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Run Code Online (Sandbox Code Playgroud)

编辑:urls.py

from django.urls import include, path
from classroom.views.classroom import current_user, UserList
from .views import classroom, suppliers, teachers
urlpatterns = [path('', classroom.home, name='home'),
               path('current_user/', current_user),
               path('users/', UserList.as_view()), …
Run Code Online (Sandbox Code Playgroud)

python api django http-post django-rest-framework

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

即使在 React 中正确导入后也不包含默认导出

我有这个简单的文件,它从另一个文件中导入 getAccesToken 常量。但即使一切都完美定义,我仍然收到此错误。我真的不知道为什么会发生这种情况。我在 SO 上看了类似的问题,但大多数在导入时都有大括号或其他东西。

PS这个问题是一个续集这个问题

这是我导入常量的文件:

import React, {Component} from 'react';
import {Card, CardBody, CardHeader, Col, Row, Table} from 'reactstrap';
import getAccessToken from '../helpers/api'   //Here is the import
import {reactLocalStorage} from "reactjs-localstorage";
import {API_TOKENS} from "../data/storage";
import {errorGettingUserInfoNotification, signINAgainNotification} from "../helpers/notifications";




class all_orders extends Component {
    state = {
        todos: []
    };


    async componentDidMount() {
        try {
            const res = await fetch('http://127.0.0.1:8000/api/allorders/',

                {
                    headers: {
                        // your headers there as pair key-value, matching what your API is …
Run Code Online (Sandbox Code Playgroud)

javascript api http django-rest-framework reactjs

3
推荐指数
3
解决办法
2万
查看次数

尽管安装并添加了路径变量,但无法在 Windows 上运行 uvicorn 命令

如标题所示,我已经使用powershell安装了uvicorn,并添加了环境变量。但每当我运行该命令时,我都会遇到同样的错误。我知道我一定在做一些小而愚蠢的事情,但是遵循 SO 上的每个答案都告诉我同样的事情,而且我根本没有任何线索。

环境变量 错误屏幕

python windows fastapi uvicorn windows-terminal

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

从字典词典中提取值

我有一本字典A:

A = {"'Delhi-Mumbai'": {6: [3]}, "'Doon-Gurgaon'": {8: [6, 9, 8, 5], 6: [7, 1, 2]}}
Run Code Online (Sandbox Code Playgroud)

我想从中提取数据,以便最终得到

extracted = {"'Delhi-Mumbai'": 6, "'Doon-Gurgaon'": [8,6]}
Run Code Online (Sandbox Code Playgroud)

我尝试运行此

for k,v in A.items():
    for i,j in v.items():
        new[k]=i
Run Code Online (Sandbox Code Playgroud)

但是此代码仅返回:

{"'Delhi-Mumbai'": 6, "'Doon-Gurgaon'": 6}
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

python dictionary python-3.x

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