Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Django views : positional argument
#1
This is probably something simple but it has eluded me so far so good.

My view looks like the following, currently:

#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
       
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

#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
My urls file looks like:

from django.urls import path

from .views import IPView, CustomAuthToken

urlpatterns = [
    path('api-token-auth/', CustomAuthToken.as_view()),
    path('ip/', IPView.as_view()),
]
Is it possible someone can spot where my issue lies? Am I making any mistakes that I didn't notice yet?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Shocked Django __init__() got an unexpected keyword argument 'any' ikurorox 2 5,389 Nov-26-2021, 07:57 PM
Last Post: ikurorox
  changing stylesheet according to variable in views AhmdMhmdWddh 0 1,529 Feb-21-2021, 12:57 PM
Last Post: AhmdMhmdWddh
  TypeError: to_capabilities() missing 1 required positional argument: 'self' OceansBlue 2 5,192 Dec-03-2020, 12:08 AM
Last Post: OceansBlue
  IndentationError: unexpected indent in views.py ift38375 1 2,505 Dec-08-2019, 02:33 PM
Last Post: michael1789
  Posting html values to views/models in Django Malt 1 2,129 Sep-04-2019, 01:44 PM
Last Post: fishhook
  TypeError: missing 1 required positional argument (word counter Django app) Drone4four 2 14,538 Jul-11-2019, 09:34 PM
Last Post: Drone4four
  Django: How to automatically substitute a variable in the admin page at Django 1.11? m0ntecr1st0 3 3,247 Jun-30-2019, 12:21 AM
Last Post: scidam
  TypeError("index() missing 1 required positional argument: 'pymydb'" nikos 2 4,213 Mar-03-2019, 09:21 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020