Получение ошибки 405 при посещении URL-адреса, который я настроил
Построение голосового чата с использованием Twilio, следуя руководству , изложенному Twilio
Я добавил это в качестве ALLOWED_HOSTS в моем settings.py:
ALLOWED_HOSTS = [
".ngrok.io",
"127.0.0.1",
"localhost"
]
Вот как настроен мой urls.py:
from django.urls import path
from .views import RoomView, TokenView
urlpatterns = [
path("rooms", RoomView.as_view(), name="room_list"),
path("token/<username>", TokenView.as_view(), name="rooms"),
]
Мои взгляды:
@method_decorator(csrf_exempt, name="dispatch")
class RoomView(View):
def post(self, request, *args, **kwargs):
room_name = request.POST["roomName"]
participant_label = request.POST["participantLabel"]
response = VoiceResponse()
dial = Dial()
dial.conference(
name=room_name,
participant_label=participant_label,
start_conference_on_enter=True,
)
response.append(dial)
return HttpResponse(response.to_xml(), content_type="text/xml")
class TokenView(View):
def get(self, request, username, *args, **kwargs):
voice_grant = grants.VoiceGrant(
outgoing_application_sid=settings.TWIML_APPLICATION_SID,
incoming_allow=True,
)
access_token = AccessToken(
settings.TWILIO_ACCOUNT_SID,
settings.TWILIO_API_KEY,
settings.TWILIO_API_SECRET,
identity=username
)
access_token.add_grant(voice_grant)
jwt_token = access_token.to_jwt()
return JsonResponse({"token": jwt_token.decode("utf-8")})
my models.py: from django.db import models
class Room(models.Model):
name = models.CharField(max_length=30)
description = models.CharField(max_length=100)
slug = models.CharField(max_length=50)
def __str__(self):
return self.name
и apps.py:
from django.apps import AppConfig
class VoiceChatConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'voice_chat'
Вот что у меня есть в родительском urls.py (тот, который я использую для других маршрутизаторов в моем приложении):
urlpatterns = [
path('', include(router.urls)),
path('admin/', admin.site.urls),
path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),
# path('api/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
path('api/token/', CustomTokenObtainPairView.as_view(), name='token_obtain_pair'),
path('api/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
path('api/token/verify/', TokenVerifyView.as_view(), name='token_verify'),
path('api/register', RegisterApi.as_view()),
path('update_profile/<int:pk>/', views.UpdateProfileView.as_view(), name='update_profile'),
path('voice_chat/', include('voice_chat.urls')),
# path('api/register', registration_view, name='register'),
# path('api/users', view.UserCreate.as_view(),name='account-create'),
# path('token-auth/', obtain_jwt_token)
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Когда я посещаю localhost:8000/voice_chat/rooms, я получаю 405 ошибку