How to show the query set result using cursor in the view












-1














I have this function that run a query and pass the result to be showed in the view.



 def index(request):
data = dict()
cursor = connection.cursor()
cursor.execute('''SELECT user.email, item.id, count(item.author_id)
FROM item INNER JOIN user on item.user_id = user.id
GROUP BY item.author_id ''')
data['item'] = cursor.fetchall();

return render(request, 'ideax/panel.html', data)


Example of the queryset result:



[('teste@gmail.com', 1, 4), ('admin@gmail.com', 2, 5)]


How can I show the result of this query in my panel.html?



I tried this one, but it doesn't works:



{% for d in item %}

{{d.email}}

{% endfor %}









share|improve this question






















  • Don't do this. Use a model.
    – Daniel Roseman
    Nov 21 '18 at 12:25










  • @DanielRoseman Could you tell me a little bit more? I didn' get it.
    – mr.abdo
    Nov 21 '18 at 12:35












  • What didn't you get? Models are a fundamental part of Django. You should go and do the tutorial.
    – Daniel Roseman
    Nov 21 '18 at 12:36










  • I tried it, but I can't got the same result of the query. I had difficult to do joins and count.
    – mr.abdo
    Nov 21 '18 at 12:39
















-1














I have this function that run a query and pass the result to be showed in the view.



 def index(request):
data = dict()
cursor = connection.cursor()
cursor.execute('''SELECT user.email, item.id, count(item.author_id)
FROM item INNER JOIN user on item.user_id = user.id
GROUP BY item.author_id ''')
data['item'] = cursor.fetchall();

return render(request, 'ideax/panel.html', data)


Example of the queryset result:



[('teste@gmail.com', 1, 4), ('admin@gmail.com', 2, 5)]


How can I show the result of this query in my panel.html?



I tried this one, but it doesn't works:



{% for d in item %}

{{d.email}}

{% endfor %}









share|improve this question






















  • Don't do this. Use a model.
    – Daniel Roseman
    Nov 21 '18 at 12:25










  • @DanielRoseman Could you tell me a little bit more? I didn' get it.
    – mr.abdo
    Nov 21 '18 at 12:35












  • What didn't you get? Models are a fundamental part of Django. You should go and do the tutorial.
    – Daniel Roseman
    Nov 21 '18 at 12:36










  • I tried it, but I can't got the same result of the query. I had difficult to do joins and count.
    – mr.abdo
    Nov 21 '18 at 12:39














-1












-1








-1







I have this function that run a query and pass the result to be showed in the view.



 def index(request):
data = dict()
cursor = connection.cursor()
cursor.execute('''SELECT user.email, item.id, count(item.author_id)
FROM item INNER JOIN user on item.user_id = user.id
GROUP BY item.author_id ''')
data['item'] = cursor.fetchall();

return render(request, 'ideax/panel.html', data)


Example of the queryset result:



[('teste@gmail.com', 1, 4), ('admin@gmail.com', 2, 5)]


How can I show the result of this query in my panel.html?



I tried this one, but it doesn't works:



{% for d in item %}

{{d.email}}

{% endfor %}









share|improve this question













I have this function that run a query and pass the result to be showed in the view.



 def index(request):
data = dict()
cursor = connection.cursor()
cursor.execute('''SELECT user.email, item.id, count(item.author_id)
FROM item INNER JOIN user on item.user_id = user.id
GROUP BY item.author_id ''')
data['item'] = cursor.fetchall();

return render(request, 'ideax/panel.html', data)


Example of the queryset result:



[('teste@gmail.com', 1, 4), ('admin@gmail.com', 2, 5)]


How can I show the result of this query in my panel.html?



I tried this one, but it doesn't works:



{% for d in item %}

{{d.email}}

{% endfor %}






python django






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 12:11









mr.abdo

467




467












  • Don't do this. Use a model.
    – Daniel Roseman
    Nov 21 '18 at 12:25










  • @DanielRoseman Could you tell me a little bit more? I didn' get it.
    – mr.abdo
    Nov 21 '18 at 12:35












  • What didn't you get? Models are a fundamental part of Django. You should go and do the tutorial.
    – Daniel Roseman
    Nov 21 '18 at 12:36










  • I tried it, but I can't got the same result of the query. I had difficult to do joins and count.
    – mr.abdo
    Nov 21 '18 at 12:39


















  • Don't do this. Use a model.
    – Daniel Roseman
    Nov 21 '18 at 12:25










  • @DanielRoseman Could you tell me a little bit more? I didn' get it.
    – mr.abdo
    Nov 21 '18 at 12:35












  • What didn't you get? Models are a fundamental part of Django. You should go and do the tutorial.
    – Daniel Roseman
    Nov 21 '18 at 12:36










  • I tried it, but I can't got the same result of the query. I had difficult to do joins and count.
    – mr.abdo
    Nov 21 '18 at 12:39
















Don't do this. Use a model.
– Daniel Roseman
Nov 21 '18 at 12:25




Don't do this. Use a model.
– Daniel Roseman
Nov 21 '18 at 12:25












@DanielRoseman Could you tell me a little bit more? I didn' get it.
– mr.abdo
Nov 21 '18 at 12:35






@DanielRoseman Could you tell me a little bit more? I didn' get it.
– mr.abdo
Nov 21 '18 at 12:35














What didn't you get? Models are a fundamental part of Django. You should go and do the tutorial.
– Daniel Roseman
Nov 21 '18 at 12:36




What didn't you get? Models are a fundamental part of Django. You should go and do the tutorial.
– Daniel Roseman
Nov 21 '18 at 12:36












I tried it, but I can't got the same result of the query. I had difficult to do joins and count.
– mr.abdo
Nov 21 '18 at 12:39




I tried it, but I can't got the same result of the query. I had difficult to do joins and count.
– mr.abdo
Nov 21 '18 at 12:39












1 Answer
1






active

oldest

votes


















0














It is returning the tuple so we have to unpack like below



{% for email, item_id, count in item %}
{{email}}
{% endfor %}


or we can also use indexes



{% for d in item %}
{{ d.0 }}
{% endfor %}





share|improve this answer





















  • It works like a charm. Tks
    – mr.abdo
    Nov 21 '18 at 12:29











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53411782%2fhow-to-show-the-query-set-result-using-cursor-in-the-view%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














It is returning the tuple so we have to unpack like below



{% for email, item_id, count in item %}
{{email}}
{% endfor %}


or we can also use indexes



{% for d in item %}
{{ d.0 }}
{% endfor %}





share|improve this answer





















  • It works like a charm. Tks
    – mr.abdo
    Nov 21 '18 at 12:29
















0














It is returning the tuple so we have to unpack like below



{% for email, item_id, count in item %}
{{email}}
{% endfor %}


or we can also use indexes



{% for d in item %}
{{ d.0 }}
{% endfor %}





share|improve this answer





















  • It works like a charm. Tks
    – mr.abdo
    Nov 21 '18 at 12:29














0












0








0






It is returning the tuple so we have to unpack like below



{% for email, item_id, count in item %}
{{email}}
{% endfor %}


or we can also use indexes



{% for d in item %}
{{ d.0 }}
{% endfor %}





share|improve this answer












It is returning the tuple so we have to unpack like below



{% for email, item_id, count in item %}
{{email}}
{% endfor %}


or we can also use indexes



{% for d in item %}
{{ d.0 }}
{% endfor %}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 '18 at 12:20









Anjaneyulu Batta

3,25511334




3,25511334












  • It works like a charm. Tks
    – mr.abdo
    Nov 21 '18 at 12:29


















  • It works like a charm. Tks
    – mr.abdo
    Nov 21 '18 at 12:29
















It works like a charm. Tks
– mr.abdo
Nov 21 '18 at 12:29




It works like a charm. Tks
– mr.abdo
Nov 21 '18 at 12:29


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53411782%2fhow-to-show-the-query-set-result-using-cursor-in-the-view%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen