Django: Я хочу отслеживать, с какого url был сделан запрос?
в классе TestQuestionList, функция get должна получить id, чтобы вернуть id, я думал, что смогу сделать это с помощью request.get_full_path()
примера внизу
class TestQuestionList(APIView):
def get(self, request):
obj = Test.objects.get(id = request.get_full_path())
romms = TestQuestionBlok.objects.filter(id__in=obj.questions)
serializer = TestQuestionSerializers(romms, many=True)
return Response(serializer.data)
но request.get_full_path()
вместо
/tests/api/
(откуда был сделан запрос)
возвращается
/api/question/
почему?
Это часть кода, откуда был сделан запрос
useEffect(() => {
axios({
method: 'GET',
url: 'http://127.0.0.1:8000/api/questions/',
}).then(response => {
setAllQuestions(response.data)
})
}, [])
urls.py
from django.urls import path
from . views import *
urlpatterns = [
path('', index),
path('api/tests/', TestList.as_view()),
path('test/<int:test_id>/', index2),
path('api/questions/', TestQuestionList.as_view()),
]
Заранее спасибо за ваши ответы