question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

does django-ninja intentionally not allow api routes like `/users/me` but require `/users/{user_id}`

See original GitHub issue

Trying to do something like:

@router.get("/users/test", response=str)
def user_test(request):
    return "hello" 

Throws error:

{
  "detail": [
    {
      "loc": [
        "path",
        "user_id"
      ],
      "msg": "value is not a valid uuid",
      "type": "type_error.uuid"
    }
  ]
}

how to get around this?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
vitalikcommented, Jul 17, 2022

@RiccardoCherchi it is the way django urls work if you know for sure that your user_id is uuid - you can help django url resolver to pin to correct path - just add uuid:user_id - it will passed to urlresolver:


@router.get("/users/{uuid:user_id}", response=str) # <------------
def user_test(request, user_id):
    return "hello" 

@router.get("/users/me", response=str)
def user_test(request):
    return "hello" 

but in case your user ids are strings - the only thing that will help is placing /user/me BEFORE /user/user_id in codebase

0reactions
RiccardoCherchicommented, Jul 17, 2022

Actually didn’t know this, Django surprise me every time, thanks for the clarification!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Defining a Schema - Django Ninja
Imagine you need to create an API operation that creates a user. The input parameter would be username+password, but output of this operation...
Read more >
Customizing permissions and responses for detail routes in ...
If a user is an admin they can use the 'post' method at the /api/v2/users url. If they are not authenticated they get...
Read more >
4 - Authentication and permissions - Django REST framework
Currently our API doesn't have any restrictions on who can edit or delete code snippets. We'd like to have some more advanced behavior...
Read more >
Setting up JWT Authentication - Thinkster.io
In Django, sessions are stored as cookies. These sessions, along with some built-in middleware and request objects, ensure that there is a user...
Read more >
Starting With REST APIs and Django Ninja - YouTube
The Django Ninja library is a FastAPI-inspired tool kit for turning Django views into REST API endpoints with very little extra code.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found