0

How do I print to the terminal the query used by a specific line of python code? see below

notifications = user.get_notifications(max_id=max_id, types=types).order_by('-created')[:count]
1
  • 2
    Welcome back to Stack Overflow. As a refresher, please read How to Ask and note well that this is not a discussion forum. Please try to look for existing answers before asking - finding the linked duplicate was as easy as putting [django] print query into the site search - and please do not make "thanks" comments - instead, see the advice at stackoverflow.com/help/someone-answers. Commented Aug 27, 2022 at 11:36

1 Answer 1

2

You can print the query by adding:

.query

after your call.

It'll look like this:

user.get_notifications(max_id=max_id, types=types).order_by('-created')[:count].query

If you're doing this in the py manage.py shell, don't forget to print() it out. Otherwise it will show a memory address.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.