Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 79637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:10:37+00:00 2026-05-10T21:10:37+00:00

I’ve just started building a prototype application in Django. I started out by working

  • 0

I’ve just started building a prototype application in Django. I started out by working through the Django app tutorial on the Django site which was pretty helpful, and gave me what I needed to get started. Now I have a couple of what I hope are very simple questions:

I want to put a loop into views.py, looping over a set of variables that have been passed in from a form. So I have a load of items in the HTML form, each of which has a SELECT drop-down list for people to select a score from 0-10, like this:

<select name='score1'>   <option value=0 SELECTED>No score</option>   <option value=1>1</option>   <option value=2>2</option>   <option value=3>3</option>   <option value=4>4</option>   <option value=5>5</option>   <option value=6>6</option>   <option value=7>7</option>   <option value=8>8</option>   <option value=9>9</option>   <option value=10>10</option> </select> 

So I have, let’s say, 100 of these variables, score1, score2, score3, …, score99, score100. When the form is submitted, I want to loop through each of these variables and see if it’s been set (i.e. is not 0) and if so, I want to store that value in a suitable place in the database. My problem is that I can’t figure out how to loop through those variables. I’m guessing that I want something like this:

for o in request.POST.all  endfor 

but then I’m really not sure what to do with that.

I’m not looking for someone to write the code for me, really: I just would like some guidance on how to write a loop like this in python / Django, and also maybe some pointers as to a good reference guide I can either see online or buy that will give me access to this kind of thing.

Also, the select object above I created pretty much by hand, and I’d really like to be able to ue a loop to generate it in the template in the first place. My template currently has this:

<table> {% for movie in movie_list %}   <tr>   <td> {{ movie }} </td>   <td>        <select name='score{{ movie.id }}'>          <option value=0 SELECTED>No score</option>          <option value=1>1</option>          <option value=2>2</option>          <option value=3>3</option>          <option value=4>4</option>          <option value=5>5</option>          <option value=6>6</option>          <option value=7>7</option>          <option value=8>8</option>          <option value=9>9</option>          <option value=10>10</option>         </select>   </td></tr>  {% endfor %} </table> 

I feel like there must be a way to create a simple loop that counts from 1 to 10 that would generate most of those options for me, but I can’t figure out how to do that…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T21:10:38+00:00Added an answer on May 10, 2026 at 9:10 pm

    You need to look at the Django forms.

    You should never build your own form like that.

    You should declare a Form class which includes a ChoiceField and provide the domain of choices to that field. Everything will happen pretty much automatically from there.

    The choices, BTW, should be defined in your Model as the range of values for that Model field.

    Your page merely includes {{form}}. Django builds the form with the choices and decodes the choices to a final result.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 118k
  • Answers 118k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try this: Select date, associate_id, count(*) as per_date From tracking… May 11, 2026 at 11:36 pm
  • Editorial Team
    Editorial Team added an answer The first commit on branch2 that's not on local-branch1 is… May 11, 2026 at 11:36 pm
  • Editorial Team
    Editorial Team added an answer If you check the documentation for that method, you will… May 11, 2026 at 11:36 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.