Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rendering dynamically generated HTML through pyramid Response

I am new to python's pyramid framework so kindly help me.

I have a HTML dynamically generated. This HTML is generated by a python script which dynamically writes (tags/tables) which are extracted from some 'xyz.html' [using beautifulsoup] to another 'abc.html'.

Now i need to send this html page ('abc.html') back as a 'Response' object of 'pyramid.response' .

how can i do this. I tried the following

    _resp = Response()
    _resp.headerlist =  [('Content-type',"text/html; charset=UTF-8'"\]
    _resp.app_iter = open('abc.html','r')
    return _resp

and also

   with open('abc.html','r') as f:
      data = f.read()
      f.close()
   return Response(data,content_type='text/html')

both did not work.

PS: I cannot use renderer="package:subpack/abc.html" or any similar renderer as this generated html is stored in a dynamically generated location everytime so i cannot guess the final storage location of this html file.

Thanks in advance for you help.

like image 676
PyBegginer Avatar asked Dec 06 '25 05:12

PyBegginer


1 Answers

I'm a little surprised your first example doesn't work. Check out this cookbook entry on it from the Pyramid docs and see if that helps.

http://docs.pylonsproject.org/projects/pyramid_cookbook/en/latest/static_assets/files.html#serving-file-content-dynamically

like image 95
Michael Merickel Avatar answered Dec 09 '25 18:12

Michael Merickel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!