当我们执行GET时,它工作得很好,但是当我们尝试进行POST时,将收到“未收到方法”错误。不知道为什么。
urls.py
from django.urls import path
from django.conf.urls import url
from . import views
urlpatterns = [
path('api/community/', views.makeCommunity),
]
views.py
@api_view(['POST'])
def makeCommunity(request):
if request.method == 'POST':
return Response(status=status.HTTP_404_NOT_FOUND)
axios代码
const API_URL = 'http://localhost:8000/api/';
export function testCommunityPost(){
return axios.post(`${API_URL}community/`)
.then(response => {
console.log(response);
console.log(response.data);
})
.catch(error => console.log(error))
}