title: Python/Pyramid: Will this function let users upload files and then parse them?
body: <p>Right now I have this form: </p>
  
  <pre><code>&lt;form action="/store_stl_data" method="post" accept-charset="utf-8"
        enctype="multipart/form-data"&gt;
  
      &lt;label for="stl"&gt;STL&lt;/label&gt;
      &lt;input id="stl" name="stl" type="file" value="" /&gt;
  
      &lt;input type="submit" value="submit" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>then in my <code>views.py</code> I have </p>
  
  <pre><code>@view_config(route_name='store_stl_data', renderer='templates/edit')
  
  def store_stl_data(request):
      input_file=request.POST['stl'].file
      i1, i2 = itertools.tee(input_file)
      vertices = [map(float, line.split()[1:4])
                  for line in i1
                  if line.lstrip().startswith('vertex')]
  
      normals = [map(float, line.split()[2:5])
                  for line in i2
                  if line.lstrip().startswith('facet')]
  
          ...(parsing data)...
      return data
  </code></pre>
  
  <p>The three lines under <code>def store_stl_data(request):</code> are the ones I am most unsure about. I got them from <a href="http://docs.pylonsproject.org/projects/pyramid_cookbook/en/latest/forms/file_uploads.html" rel="nofollow">this tutorial</a>. </p>
  
  <p>I want it so that when people upload the file, the entire <code>store_stl_data</code> function runs and processes the input file. </p>
  
  <p>Right now it gives me an error:</p>
  
  <pre><code>KeyError: "No key 'stl': Not a form request"
  </code></pre>
  
  <p>Also here is my route, in <code>__init__.py</code>:</p>
  
  <pre><code>from pyramid.config import Configurator
  from sqlalchemy import engine_from_config
  
  from .models import (
      DBSession,
      Base,
      )
  
  
  def main(global_config, **settings):
      """ This function returns a Pyramid WSGI application.
      """
      engine = engine_from_config(settings, 'sqlalchemy.')
      DBSession.configure(bind=engine)
      Base.metadata.bind = engine
      config = Configurator(settings=settings)
      config.add_static_view('static', 'static', cache_max_age=3600)
      config.add_route('view_wiki', '/')
      config.add_route('view_page', '/{pagename}')
      config.add_route('add_page', '/add_page/{pagename}')
      config.add_route('edit_page', '/{pagename}/edit_page')
      config.scan()
      return config.make_wsgi_app()
  </code></pre>