Numeric for loop in Django templates
How do I write a numeric for loop in a Django template? I mean something like for i = 1 to n 21 Answers 21
How do I write a numeric for loop in a Django template? I mean something like for i = 1 to n 21 Answers 21
models.py: class Person(models.Model): name = models.CharField(max_length=200) CATEGORY_CHOICES = ( (‘M’, ‘Male’), (‘F’, ‘Female’), ) gender = models.CharField(max_length=200, choices=CATEGORY_CHOICES) to_be_listed = models.BooleanField(default=True) description = models.CharField(max_length=20000, blank=True) views.py: def index(request): latest_person_list2 = Person.objects.filter(to_be_listed=True) return object_list(request, template_name=”polls/schol.html”, queryset=latest_person_list, paginate_by=5) On the template, when I call person.gender, I get ‘M’ or ‘F’ instead of ‘Male’ or ‘Female’. How to … Read more
I have the following for loop in my django template displaying days. I wonder, whether it’s possible to iterate a number (in the below case i) in a loop. Or do I have to store it in the database and then query it in form of days.day_number? {% for days in days_list %} <h2># Day … Read more
I was wondering how to get the current URL within a template. Say my current URL is: …/user/profile/ How do I return this to the template? 16 Answers 16
I have some stuff in settings.py that I’d like to be able to access from a template, but I can’t figure out how to do it. I already tried {{CONSTANT_NAME}} but that doesn’t seem to work. Is this possible? 17 Answers 17