How to show the query set result using cursor in the view
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
add a comment |
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
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
add a comment |
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
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
python django
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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 %}
It works like a charm. Tks
– mr.abdo
Nov 21 '18 at 12:29
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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 %}
It works like a charm. Tks
– mr.abdo
Nov 21 '18 at 12:29
add a comment |
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 %}
It works like a charm. Tks
– mr.abdo
Nov 21 '18 at 12:29
add a comment |
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 %}
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 %}
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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