title: Inserting a request.form.items() list into a mongodb collection / Adding list of lists into mongoDB
body: <p>I have the following code:</p>
  <pre><code>@app.route(&quot;/create&quot;, methods=[&quot;POST&quot;, &quot;GET&quot;])
  @login_required
  def create():
      if request.method == &quot;POST&quot;:    
          list = []
          for x in request.form.items():
              if x[0] == &quot;date&quot;:
                  datefc = datetime.strptime(x[1], &quot;%Y-%m-%d&quot;)
              elif x[0] == &quot;frequency&quot;:
                  frequency = x[1]
              elif x[0] == &quot;submit&quot;:
                  continue
              else:
                  list.append(x)
  
          adate = datetime.today()
  
          if frequency == &quot;Weekly&quot;:
              nContactTime = datefc + timedelta(days=7)
          elif frequency == &quot;Monthly&quot;:
              nContactTime = datefc + timedelta(days=30)
          elif frequency == &quot;Quarterly&quot;:
              nContactTime = datefc + timedelta(days=90)
  
          people.insert_one({list, &quot;frequency&quot;: frequency, &quot;parentrecord&quot;: current_user.user_json['_id'], &quot;dateadded&quot;: adate.strftime(&quot;%x&quot;),&quot;datefc&quot;: datefc, &quot;nextContact&quot;: nContactTime})
  
          flash('Your record has been entered successfully.')
          return redirect(url_for('profile'))
  </code></pre>
  <p>I use <code>for x in request.form.items()</code> to loop through a dynamically generated form. Users create custom fields that can be added. I then add the results to a list of which an example of a print out is:</p>
  <p><code>[('name', 'David'), ('phone', '90'), ('email', 'inf'), ('company', 'Ran'), ('Kids Names', 'Kids Names'), ('Kids Birthday', '2022-08-03'), (&quot;Wife's Email&quot;, 'Test@test.com')]</code></p>
  <p>My issue is when I attempt to run the code I get a syntax error:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;C:\Users\David PC\AppData\Local\Programs\Python\Python310\lib\runpy.py&quot;, line 196, in _run_module_as_main
      return _run_code(code, main_globals, None,
    File &quot;C:\Users\David PC\AppData\Local\Programs\Python\Python310\lib\runpy.py&quot;, line 86, in _run_code
      exec(code, run_globals)
    File &quot;C:\Users\David PC\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\__main__.py&quot;, line 3, in &lt;module&gt;
      main()
    File &quot;C:\Users\David PC\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\cli.py&quot;, line 986, in main
      cli.main()
    File &quot;C:\Users\David PC\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\cli.py&quot;, line 567, in main
      return super().main(*args, **kwargs)
    File &quot;C:\Users\David PC\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py&quot;, line 1055, in main
      rv = self.invoke(ctx)
    File &quot;C:\Users\David PC\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py&quot;, line 1657, in invoke
      return _process_result(sub_ctx.command.invoke(sub_ctx))
    File &quot;C:\Users\David PC\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py&quot;, line 1404, in invoke
      return ctx.invoke(self.callback, **ctx.params)
    File &quot;C:\Users\David PC\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py&quot;, line 760, in invoke
      return __callback(*args, **kwargs)
    File &quot;C:\Users\David PC\AppData\Local\Programs\Python\Python310\lib\site-packages\click\decorators.py&quot;, line 84, in new_func
      return ctx.invoke(f, obj, *args, **kwargs)
    File &quot;C:\Users\David PC\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py&quot;, line 760, in invoke
      return __callback(*args, **kwargs)
    File &quot;C:\Users\David PC\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\cli.py&quot;, line 848, in run_command
      app = DispatchingApp(info.load_app, use_eager_loading=eager_loading)
    File &quot;C:\Users\David PC\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\cli.py&quot;, line 279, in __init__
      self._load_unlocked()
    File &quot;C:\Users\David PC\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\cli.py&quot;, line 313, in _load_unlocked
      self._app = rv = self.loader()
    File &quot;C:\Users\David PC\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\cli.py&quot;, line 373, in load_app
      app = locate_app(import_name, None, raise_if_not_found=False)
    File &quot;C:\Users\David PC\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\cli.py&quot;, line 214, in locate_app
      __import__(module_name)
    File &quot;C:\Users\David PC\Desktop\VS Code Python\Flask Site\app.py&quot;, line 150
      people.insert_one({list, &quot;frequency&quot;: frequency, &quot;parentrecord&quot;: current_user.user_json['_id'], &quot;dateadded&quot;: adate.strftime(&quot;%x&quot;),&quot;datefc&quot;: datefc, &quot;nextContact&quot;: nContactTime})
                                          ^
  SyntaxError: invalid syntax
  
  Process finished with exit code 1
  </code></pre>
  <p>I am fairly confident the issue arises that my list is improperly formated (or my insert is). I've tried converting it using <code>json_dumps</code>, etc and nothing seems to work. Assistance would be appreciated!</p>