Skip to content

About paging query #452

Answered by SmileyChris
wu-clan asked this question in Q&A
May 19, 2022 · 6 comments · 5 replies
Discussion options

You must be logged in to vote

Ah, I see what you're saying now -- it's specifically when you're trying to return a different response type, which you can't do with the paginate decorator. That could definitely do with some better documentation.

What you can do though is raise an exception that ninja will handle. And by default, it handles Django's Http404 error like you want. So all you want is:

from django.shortcuts import get_object_or_404

...

@paginate
def get_group_users(request, pk: int):
    return get_object_or_404(Group, id=pk).user.all()

Replies: 6 comments 5 replies

Comment options

You must be logged in to vote
1 reply
@mom1
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@SmileyChris
Comment options

Comment options

You must be logged in to vote
2 replies
@SmileyChris
Comment options

@wu-clan
Comment options

Comment options

You must be logged in to vote
1 reply
@wu-clan
Comment options

Answer selected by wu-clan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants