【发布时间】:2021-06-07 04:17:25
【问题描述】:
我在尝试使用 url 时得到 page_not_found:
from django.urls import path from . import views
urlpatterns = [
path('api/v1/posts/<int:post_id>/', views.get_post, name='get_post'), ]
到我在小型 Django 项目中的视图功能:
from django.http import JsonResponse
from rest_framework.response import Response
def get_post(post_id):
if request.method == 'GET':
post = get_object_or_404(Post, id=post_id)
serializer = PostSerializer(post)
return JsonResponse(serializer.data)
寻求帮助)
【问题讨论】:
-
尝试使用 api/v1/posts/
/ 而不是 api/v1/posts/int:post_id/。注意“”
标签: python django http-status-code-404