я создал несколько URL с маршрутизатором по умолчанию, как показано ниже:
api.urls
from django.urls import path, include
from rest_framework import routers
from rest_framework_bulk.routes import BulkRouter
from . import views
router = routers.DefaultRouter()
#### NEW ####
router.register(r'data/credentials/', views.DataCredentials)
router.register(r'data/site_circuits', views.DataSiteCircuits)
router.register(r'data/subnets/', views.SubnetsSet)
router.register(r'data/device_conns/', views.DataDeviceConns)
router.register(r'data/email_subscriber/', views.DataEmailSubscriber)
router.register(r'data/pd_user/', views.DataOnCall)
router.register(r'data/bgp/', views.DataBGP)
router.register(r'data/device/routingtable/', views.DataDeviceRoutingTable)
router.register(r'monitoring/bgp/', views.MonitoringBGP)
router.register(r'monitoring/script_results/', views.MonitoringScriptResults)
router.register(r'monitoring/circuit_maintenance/', views.MonitoringCircuitMaintenance)
router.register(r'monitoring/device/routingtable/', views.MonitoringDeviceRoutingTable)
#### LEGACY ####
router.register(r'credentials', views.CredentialDataROView)
router.register(r'tasks', views.TaskSet)
router.register(r'subnets', views.SubnetsSet)
router.register(r'device_conns', views.DeviceConnViewSet)
router.register(r'script_results', views.ScriptResultsView)
router.register(r'circuit_maintenance', views.CircuitMaintenanceView)
router.register(r'email_subscriber', views.EmailSubscriberROView)
router.register(r'pd_user', views.OnCallROView)
router.register(r'bgp_monitoring_data', views.BGPMonitoringDataView)
router.register(r'bgp_status', views.BGPStatusView)
router.register(r'rt_get_devices', views.MonitoringRoutingTableGetDevice)
router.register(r'rt_get_tables', views.MonitoringRoutingTableGet)
router.register(r'rt_upload', views.MonitoringRoutingTableUpload)
router.register(r'contact_type', views.ContactTypeROView)
# Wire up our API using automatic URL routing.
# Additionally, we include login URLs for the browsable API.
urlpatterns = [
path('', include(router.urls)),
path('api-auth/', include('rest_framework.urls')),
#### NEW ####
path('data/site_subnets/', views.DataSiteSubnets.as_view()),
path('data/site_circuits_subnets/', views.DataSiteCircuitSubnets.as_view()),
path('data/device/routing_table/', views.DataDeviceRoutingTable.as_view({'get': 'list','put': 'update'})),
path('data/geomapping/', views.DataGeoMapping.as_view()),
path('monitoring/oncall/', views.MonitoringOnCall.as_view()),
path('monitoring/site_connectivity/', views.MonitoringSiteConnectivity.as_view()),
#### LEGACY ####
path('ss_monitoring_data/', views.SiteSupernetMontioringDataROView.as_view()),
path('monitoring/routing_data', views.MontioringGetRoutingData.as_view()),
path('conn_set_single/<int:site_id>/<int:circuit_id>/', views.MonitoringConnectivitySetSingle.as_view()),
path('conn_set/', views.MonitoringConnectivitySet.as_view()),
path('site_circuits_pending/<int:days>/', views.SiteCircuitsPendingDataROView.as_view({'get': 'list'})),
path('upcoming_circuit_maintenance/<int:days>/', views.UpcomingCircuitMaintenanceView.as_view({'get': 'list'})),
path('aws_bgpdata_set/', views.MonitoringBGPDataSet.as_view()),
path('aws_dc_set/', views.MonitoringAWSDirectConnectSet.as_view()),
path('aws_vpn_set/', views.MonitoringAWSVPNSet.as_view()),
path('four_g_set/', views.FourGDataSet.as_view()),
path('contact_set/', views.ContactSet.as_view()),
path('site_contact_set/', views.SiteContactSet.as_view()),
path('device_version_set/', views.DeviceVersionSet.as_view()),
]
home.urls
from django.urls import path
from . import views
app_name = 'home'
urlpatterns = [
path('', views.index, name='index'),
....
и затем я пытаюсь чтобы попасть по URL http://localhost: 8100 / api / data / device / routingtable / , и меня встретит 404, кто-нибудь узнает, почему это так?
и когда я нажму Домашняя страница API и список URL-адресов, они отображаются на неправильные представления:
HTTP 200 OK
Allow: GET, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept
{
...
"data/device/routingtable/": "http://localhost:8100/api/rt_upload/",
...
}
views.py:
class DataDeviceRoutingTable(viewsets.ModelViewSet):
time_threshold = datetime.now() - timedelta(minutes=2)
queryset = DeviceData.objects.all().select_related('device','device_use').order_by('monitoring_order')
serializer_class = SerializerDataRoutingTable
permission_classes = (IsAdminUser,)
filter_class = DeviceData
filter_backends = (filters.SearchFilter,)
search_fields = ('device__hostname','device_use__use')
serialisers.py:
class SerializerDataRoutingTable(serializers.ModelSerializer):
hostname = serializers.ReadOnlyField(source='device.hostname', )
site_id = serializers.ReadOnlyField(source='device.site_id', )
routing_table = serializers.SerializerMethodField(source='routing_table',)
use = serializers.ReadOnlyField(source='device_use.use', )
def get_routing_table(self, instance):
try:
return json.loads(instance.routing_table)
except:
return instance.routing_table
class Meta:
model = DeviceData
fields = ('id','site_id','device_id','hostname','use', 'timestamp', 'routing_table')
depth = 1
urls.py:
from django.urls import path, include
from django.conf import settings
from django.contrib.auth import views as auth_views
from django.contrib import admin
import app_settings.views
admin.autodiscover()
handler400 = 'app_settings.views.bad_request'
handler403 = 'app_settings.views.permission_denied'
handler404 = 'app_settings.views.page_not_found'
handler500 = 'app_settings.views.server_error'
urlpatterns = [
path('', include('home.urls')),
path('api/', include('api.urls')),