Nov-15-2021, 06:02 PM
This is probably something simple but it has eluded me so far so good.
My view looks like the following, currently:
While the above works, passing ip as a positional argument and not as query parameter fails to match any url. My understanding is that the below should also work but it does not because the request fails to match any url
My urls file looks like:
Is it possible someone can spot where my issue lies? Am I making any mistakes that I didn't notice yet?
My view looks like the following, currently:
1 2 3 4 5 6 7 8 9 |
#request - /ip/?ip=172.69.89.90 class IPView(APIView): permission_classes = (IsAuthenticated,) def get( self , request, format = None ): ip = int (ipaddress.IPv4Address(request.query_params[ 'ip' ])) #do something with the ip and give a response |
1 2 3 4 5 6 7 |
#request /api/172.89.90.25 class IPView(APIView): permission_classes = (IsAuthenticated,) def get( self , request, ip, format = None ): #do something with the ip and give a response |
1 2 3 4 5 6 7 8 |
from django.urls import path from .views import IPView, CustomAuthToken urlpatterns = [ path( 'api-token-auth/' , CustomAuthToken.as_view()), path( 'ip/' , IPView.as_view()), ] |