Speak now
Please Wait Image Converting Into Text...
Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Challenge yourself and boost your learning! Start the quiz now to earn credits.
Unlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
General Tech Bugs & Fixes 2 years ago
Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.
Turn Your Knowledge into Earnings.
I'm trying to make a quiz app using Django, Jinja2 and PostgreSQL. I want to number the questions but I don't know how to because python doesn't use a counter in for loops (e.g. for exercise in exercises - no for loop here)
I've tried to change the for loop
(for exercise in exercises)
so it has a counter
(for x in myrange)
and defining myrange in views.py to be a range(1, len(exercitii+1)) but after that I didn't know how to access the elements inside the Jinja template. I tried to access the exercises with
{exercitii.x-1.intrebare}}
but it didn't work.
html template
{% extends 'base.html' %} {% load static %} {% block content %} div> <div id="middle-section" class="container-fluid container-fluid-margin"> <div class="content-quiz"> <form action="{% url 'exercitiu' lectii.id %}" method="POST" id="quiz"> {% for exercitiu in exercitii %} <div class="row content-block"> <div class="col-lg-10 text-card"> {% csrf_token %} <div class="card card-custom"> <div class="card-body"> <h5 class="card-title">{{exercitiu.id}} - {{exercitiu.intrebare}}h5> <div class="card-text"> <input type="radio" name="question-{{exercitiu.id}}-answers" id="question-{{exercitiu.id}}-answers-A" value="A" /> <label for="question-{{exercitiu.id}}-answers-A">A) {{exercitiu.variante.0}} label> div> <div class="card-text"> <input type="radio" name="question-{{exercitiu.id}}-answers" id="question-{{exercitiu.id}}-answers-B" value="B" /> <label for="question-{{exercitiu.id}}-answers-B">B) {{exercitiu.variante.1}} label> div> <div class="card-text"> <input type="radio" name="question-{{exercitiu.id}}-answers" id="question-{{exercitiu.id}}-answers-C" value="C" /> < REPLY 0 views 0 likes 0 shares Facebook Twitter Linked In WhatsApp
If I got your question correctly, you want to get the iteration number of the for loop in jinja.
Jinja provides a very convenient loop variable, it has a property called loop.counter which is 1-indexed, and loop.counter0 which is 0-indexed. View Docs
And if you're using DjangoTemplate, then those become forloop.counter0 and forloop.counter. View Docs
No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
General Tech 10 Answers
General Tech 7 Answers
General Tech 3 Answers
General Tech 9 Answers
General Tech 2 Answers
Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.