0

I am dynamically generating a html page from data in the database(mainly labels retrieved since I'm in the stage of CREATING data to store in the db). I retrieve labels and id's from the database, then store it in a class which I return to jinja2 so that I can then dynamically generate all the labels and input boxes. Here is a snippet:

<div class="dataDiv">
            <label class="inputBoxLabels">Device<span style="padding-left: 85px;font-size: 12px;"><a href="http://127.0.0.1:6543/new_device/1">New</a></label>
            <select id="devices" class="inputBoxes" style="height: 25px;">
                {% for key, value in devices.iteritems() %}
                    {% if deviceID == key %}
                        <option value="{{ key }}" selected="selected">{{ value }}</option>
                    {% else %}
                        <option value="{{ key }}">{{ value }}</option>
                    {% endif %}
                {% endfor %}
            </select>
        </div>

another example, this time an input box:

{% if inspection.statusDict|length > 0 %}
    <select class="inputBoxes" id="ins_' + {{ inspection.insID }} + '" style="height: 25px;">
        {% for key, value in inspection.statusDict.iteritems() %}
            <option value="{{key}}">{{value}}</option>
        {% endfor %}
    </select>
{% else %}
   <input type="text" class="inputBoxes" id="ins_' + {{ inspection.insID }} + '">
{% endif %}

This is what the select list looks like after is has been populated for visual reference: enter image description here

Now the problem. I have everything inside a form and I have no idea how to retrieve the data from each input and select when I receive the post since it's all dynamically generated.

I originally thought of using jquery instead and ajax but if possible I'd like to stick to forms

1 Answer 1

2

Off the top of my head I think if you're submitting to a Pyramid view via POST you should be able to iterate over request.POST to get whatever was submitted.

Something like and inspect each item

for item in request.POST.keys():
  print item + ' - ' + request.POST[item]

I'd have to try it when I get home to a console to confirm.

Sign up to request clarification or add additional context in comments.

1 Comment

thank you. I've never done form posts really and especially not in python. This was really helpful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.