当我尝试 127.0.0.1:8000/api/ 时它可以工作,但是当我尝试 127.0.0.1:8000/api/rota 时它不工作。
我不知道出了什么问题。当链接 urls.py 文件时。
文件代码如下:url.py
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('base.urls')),
**path('api/', include('base.api.urls'))**,
]
I included the api/urls.py
below the code of the file: api/url.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.getMessage),
path('rota/', views.getRoutes),
]
I linked the url with methods.
below the code of the file: api/view.py
from rest_framework.decorators import api_view
from rest_framework.response import Response
@api_view(['GET'])
def getRoutes(request):
routes=[
'GET api/'
'GET api/rota'
]
return Response(routes)
@api_view(['GET'])
def getMessage(request):
return Response("ok!")
Does someone know how to fix it?
Here some pictures about the case:
[127.0.0.1:8000/api/][1]
[127.0.0.1:8000/api/][2]
[1]: https://i.stack.imgur.com/c7CoF.png
[2]: https://i.stack.imgur.com/b5cok.png
I am looking for a solution...
访问 getRoutes 视图的正确 URL 应该是 127.0.0.1:8000/api/rota/