Django: display object's another field from template tag? -


i have objects in database, each object has 2 values(fields): 'id' , 'name'.

i want request model template tags display field of object, when first 1 given.

example.

model: fruits  objects:  name:banana id:1 name:apple id:2 name:orange id:3 

how make request template tag ask like: 'display name of object id=1' or 'display id of object named orange'?

dos here: a shortcut: get_object_or_404().i made modifications make easier understand.

from django.shortcuts import get_object_or_404, render  .models import question # ... def detail(request, question_id):     # object here     question = question.objects.all()     return render(request, 'polls/detail.html', {'question': question}) 

and in templetes

{% qu in question %}   <li><a href="/polls/{{ question.id }}/">{{ question.question_text }}</a></li> {% endfor %} 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -