Search
 
SCRIPT & CODE EXAMPLE
 

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 %}
Comment

PREVIOUS NEXT
Code Example
Python :: remove exif from image 
Python :: test a decorator python 
Python :: google.api_core.exceptions.ServiceUnavailable: 503 The datastore operation timed out, or the data was temporarily unavailable when using stream 
Python :: implementation of binary search tree in python 
Python :: Print Multiple Variables 
Python :: custom save method django 
Python :: python stop running instances 
Python :: python if block 
Python :: Django is MVT Not MVC 
Python :: handling image files django aws 
Python :: Collections module: deques and queues 
Python :: Function to stop a while loop 
Python :: PySimpleGUI and tkinter with camera on Android 
Python :: intersection_update() Function of sets in python 
Python :: python Least prime factor of numbers till n 
Python :: python if modulo 
Python :: how to fix value error in model.fit 
Python :: geopandas plot raster and vector 
Python :: Function argument unpacking in python 
Python :: pytrend 
Python :: how to write def 
Python :: data structures in python 
Python :: python iterate through lists itertools 
Python :: cgi in python; get() method 
Python :: python import only one function 
Python :: repeat printing rows excel using python whenever i run the script 
Python :: oauthlib python error 
Python :: strategy forex with python 
Python :: django.com 
Python :: how to analyze data from dataframe in python 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =