In Django, how to extract ID attribute from html Input tag, WITHOUT using django forms

lenz

Suppose I’m wanting to extract some data from an html form on POST event, NOT in a django form.

In my views.py I can call “request.POST” and I get a dictionary of “name and value”. But in this case the names are all the same.

Is there a way that I can get the “id” instead of the name for example? w/o changing the html in the template ?

Pretty much a rookie here, don’t be too harsh on me

Here’s a snippet of the django template :

<!-- Radio Buttons -->
            <div class="form__group">
              <div class="form__radio-group">
                <input class="form__radio-input" type="radio" id="year1" name="year">
                <label class="form__radio-label" for="year1">
                  <span class="form__radio-button"></span>
                  1st year
                </label>
              </div>

              <div class="form__radio-group">
                <input class="form__radio-input" type="radio" id="year2" name="year">
                <label class="form__radio-label" for="year2">
                  <span class="form__radio-button"></span>
                  2nd year
                </label>
              </div>

              <div class="form__radio-group">
                <input class="form__radio-input" type="radio" id="year3" name="year">
                <label class="form__radio-label" for="year3">
                  <span class="form__radio-button"></span>
                  3rd year
                </label>
              </div>

              <div class="form__radio-group">
                <input class="form__radio-input" type="radio" id="year4" name="year">
                <label class="form__radio-label" for="year4">
                  <span class="form__radio-button"></span>
                  4th year
                </label>
              </div>
            </div>
lenz

For reference, I've solved this by using "value=1", as suggested by WillemVanOnsem in the comments, as such:

        <!-- Radio Buttons -->
            <div class="form__group">
              <div class="form__radio-group">
                <input class="form__radio-input" type="radio" id="year1" name="year" value=1>
                <label class="form__radio-label" for="year1">
                  <span class="form__radio-button"></span>
                  1st year
                </label>
              </div>

              <div class="form__radio-group">
                <input class="form__radio-input" type="radio" id="year2" name="year" value=2>
                <label class="form__radio-label" for="year2">
                  <span class="form__radio-button"></span>
                  2nd year
                </label>
              </div>

              <div class="form__radio-group">
                <input class="form__radio-input" type="radio" id="year3" name="year" value=3>
                <label class="form__radio-label" for="year3">
                  <span class="form__radio-button"></span>
                  3rd year
                </label>
              </div>

              <div class="form__radio-group">
                <input class="form__radio-input" type="radio" id="year4" name="year" value=4>
                <label class="form__radio-label" for="year4">
                  <span class="form__radio-button"></span>
                  4th year
                </label>
              </div>
            </div>

The POST request sends out the value (ie: 1 for year 1), which is what I wanted to accomplish!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to extract values from HTML <input type="date"> using jQuery

Web Forms For Marketters (WFFM) Html input tag with placeholder attribute

How to extract Django Form errors message without the HTML tags

Django: Get LIST data from HTML without forms or models

How to extract id and url from an anchor tag in this code using PHP?

How do I implement text forms(?) using django or HTML

Passing HTML input tag value to Django view

extract a html ID from inside a tag using beautiful soup python

How to find elements without using the tag attribute?

Extract property id from attribute using xpath

How to populate html input in Django framework without using a any of Django form?

Django forms adding class attribute from the constructor

How can I extract submitbuttonnextstatusid value from a rendered HTML from an input tag whose id is "submitbutton"?

Django Forms - How to change an attribute from a field?

How to extract / edit an attribute from a html tag using javascript or angularjs?

Python/Django date field in html input tag

How would I extract a specific attribute from a tag with a fuzzy id?

How to get the value of a single attribute from a HTML tag using Beautifulsoup?

get tag attribute from html using find

How to extract an HTML tag by ID?

Using the object id in django forms

How to use the images taken from user using input tag HTML?

How to display value from the database in input tag in django?

Extract a variable length ID from a HTML tag

How to fill html "option" tag with data from database in Django?

How to specify camera capture in input tag using Django?

How to extract data from an html form using django?

django: How do i save form in django without the django forms?

How to extract multiline content from the <pre> tag in html using Selenium