Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how can i get the data from a queryset in django template

Make sure the view contains the .Value() param
In Views.py
class LfrReportChapterOneView(PermissionRequiredMixin, TemplateView):
    template_name = "../templates/dashboards/lfr/lfr_report_chapitre1_create.html"

    def get_context_data(self, **kwargs):
        context = super(LfrReportChapterOneView, self).get_context_data(**kwargs)
        context["questions"] = ChapterQuestions.objects.filter(chapter_id=1).order_by("question_id").values()
        return context
      
In html file 
{% for qst in questions %}
      <tr>
      <td width="70%" style="font-weight: 400">{{ qst.question_wording }}:</td>
      <td><input type="text" placeholder="{{ qst.question_wording }}" class="test test2" required></td>
      </tr>
      {% endfor %}
 
PREVIOUS NEXT
Tagged: #data #queryset #django #template
ADD COMMENT
Topic
Name
5+4 =