title: How can I create a file with a variable name in pyramid?
body: <pre><code>@view_config(route_name='home_page', renderer='templates/edit.pt')
  def home_page(request):
      if 'form.submitted' in request.params:
          name= request.params['name'] 
          body = request.params['body'] 
          renderer_dict = dict(name=name,body=body) 
          new_comment = render('new_page.pt', renderer_dict, request=request) 
          with open('tutorial:templates/{name}.html','w') as file:
              file.write(new_comment)  
          return HTTPFound(location=request.static_url('tutorial:pages/{pagename}.html',pagename=name)) 
  
      return {} 
  </code></pre>
  
  <p>Right now this is a view callable I have in my pyramid app that is for my apps home page. I am concerned about the line where file is created (with open...). I want the name of the file to be the same name defined by the request.params in the code above but I am not sure how to pass the variable (I doubt brackets are the right solution). I then want .html to be added to that name to make it a full file name. I am not sure what syntax to use in order to do this </p>
  
  <p>Edit: I also would like advice on how to correctly do this on the return HTTPFound line. I would like it to redirect to that new file. Right now I have {pagename}.html but doubt that this is sufficient. I feel like the solution to this is the same as to the with open line but please correct me if Im wrong. </p>