1

I have a Django view like this:

def viewA(request):
    if request.POST.get('Go'):
       # Get all fields
       all = {}
       for key, values in request.POST.lists():
           all[key]=values
       print (all)

With this html:

<label>Numero de telefono</label>
<input type="text" name="phone" autocomplete="off"/>
<input type="submit" name="Go" value="Send">

When i click 'Go' button, i get "all" dict with the phone value inside. Ok.

My problem is that i have another view where i create input elements with a template like this:

<div>
    {% for table, campos in tables.items %}
        <div class="taable">
            <label>{{table}}</label>
                {% for campo in campos %}
                    <div class="caampo">
                        <input type="text" value="{{campo}}" disabled name="{{table}}:{{campo}}"/>
                        <select>
                            <option>Varchar</option>
                            <option>Int</option>
...

In this case, when i click 'Go' button don't retrieve the data for this elements created dynamically with django template. How can I get this?

Thanks!

Marc
  • 35
  • 4
  • In your view you are first accessing `request.GET` and later `request.POST`. Try changing it to use the same both times. – Ralf May 01 '18 at 00:12
  • if you post the whole form html, maybe we can help, the bug can be not in the shortcodes that you have posted – Lemayzeur May 01 '18 at 05:45
  • @Ralf sorry! It was a mistake when i put code here. In my view i use POST in the both times... – Marc May 01 '18 at 08:43

1 Answers1

0

Disabled inputs are not submitted in POST requests.

# your input elements
<input type="text" value="{{campo}}" disabled name="{{table}}:{{campo}}"/>

Remove the disabled attribute from the inputs.

Maybe you could use readonly instead. See also these related questions:

  1. Disabled form inputs do not appear in the request
  2. values of disabled inputs will not be submitted?
Ralf
  • 16,086
  • 4
  • 44
  • 68