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:

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

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

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()),
]
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
  TypeError: __init__() missing 1 required positional argument: 'instructions' SecRec01 5 5,244 Jul-07-2024, 11:03 AM
Last Post: snippsat
Shocked Django __init__() got an unexpected keyword argument 'any' ikurorox 2 7,888 Nov-26-2021, 07:57 PM
Last Post: ikurorox
  changing stylesheet according to variable in views AhmdMhmdWddh 0 2,125 Feb-21-2021, 12:57 PM
Last Post: AhmdMhmdWddh
  TypeError: to_capabilities() missing 1 required positional argument: 'self' OceansBlue 2 7,037 Dec-03-2020, 12:08 AM
Last Post: OceansBlue
  IndentationError: unexpected indent in views.py ift38375 1 3,184 Dec-08-2019, 02:33 PM
Last Post: michael1789
  Posting html values to views/models in Django Malt 1 2,792 Sep-04-2019, 01:44 PM
Last Post: fishhook
  TypeError: missing 1 required positional argument (word counter Django app) Drone4four 2 16,936 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 4,575 Jun-30-2019, 12:21 AM
Last Post: scidam
  TypeError("index() missing 1 required positional argument: 'pymydb'" nikos 2 5,276 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