Невозможно получить доступ к конечным точкам Django
Не удается получить доступ к различным конечным точкам Django. Пробовал обращаться к таким конечным точкам, как http://127.0.0.1:8000/api/line-chart-data/ http://127.0.0.1:8000/api/candlestick-data/ и т.д., но получил ответ 404.
urls.py
"""
URL configuration for mysite project.
The `urlpatterns` list routes URLs to For more information please see:
https://docs.djangoproject.com/en/5.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
# mysite/urls.py
from django.contrib import admin
from django.urls import path
from .views import line_chart_data, candlestick_data, bar_chart_data, pie_chart_data
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('charts.urls')),
path('api/candlestick-data/', candlestick_data),
path('api/line-chart-data/', line_chart_data),
path('api/bar-chart-data/', bar_chart_data),
path('api/pie-chart-data/', pie_chart_data),
]
views.py
# mysite/views.py
from rest_framework.response import Response
from rest_framework.decorators import api_view
@api_view(['GET'])
def candlestick_data(request):
data = {
"data": [
{"x": "2023-01-01", "open": 30, "high": 40, "low": 25, "close": 35},
{"x": "2023-01-02", "open": 35, "high": 45, "low": 30, "close": 40},
]
}
return Response(data)
@api_view(['GET'])
def line_chart_data(request):
data = {
"labels": ["Jan", "Feb", "Mar", "Apr"],
"data": [10, 20, 30, 40]
}
return Response(data)
@api_view(['GET'])
def bar_chart_data(request):
data = {
"labels": ["Product A", "Product B", "Product C"],
"data": [100, 150, 200]
}
return Response(data)
@api_view(['GET'])
def pie_chart_data(request):
data = {
"labels": ["Red", "Blue", "Yellow"],
"data": [300, 50, 100]
}
return Response(data)
settings.py
Вставлял различные энпоинты, чтобы получить данные в формате json, но вместо этого получил 404. Конечные точки:
http://127.0.0.1:8000/api/line-chart-data/ http://127.0.0.1:8000/api/candlestick-data/ и т.д.