Question

I have a form where you have the option to add upload inputs. I want the images that will be uploaded with every input to be grouped together (there will be text in between). Every time an upload button is added it get's the name "upload_image1", "upload_image2", ...

I want to check if these names are defined so i can then loop through them later. I am trying to combine upload_image and an integer that is counting up together but it looks like he is trying to add that integer to the value of upload_image which is not defined.

if len(form["upload_image1"]) > 0:
    while 1:
        field_count = 1
        if len(form["upload_image" + str(field_count)]) == 0: break
        upload_field = form["upload_image" + str(field_count)]
        upload_image += upload_field
        article_content += """
                            <p>%s</p>
                            """ % (description[field_count].value)
        for item in upload_field:
            article_content += '<img src="http://www.******.com/images/%s/%s">' % (link_title, item.filename)
        field_count = field_count + 1
Was it helpful?

Solution 2

I fixed the Memory Error. I accidentally put field_count = 1 inside my loop so it kept resetting itself. The rest apparently works just fine. Thanks for the help!

OTHER TIPS

Here is how to avoid the KeyError:

  • If form["upload_image1"] is a string, then use form.get("upload_image1", "") instead.
  • If form["upload_image1"] is a sequence (e.g. list or tuple), then use form.get("upload_image1", ()) instead.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top