manage.py runserver

You can run it for machines in your network by ./manage.py runserver 0.0.0.0:8000 And than you will be able to reach you server from any machine in your network. Just type on other machine in browser http://192.168.0.1:8000 where 192.168.0.1 is IP of you server… and it ready to go…. or in you case: On machine …

Read more

Python unittest.TestCase execution order

Don’t make them independent tests – if you want a monolithic test, write a monolithic test. class Monolithic(TestCase): def step1(self): … def step2(self): … def _steps(self): for name in dir(self): # dir() result is implicitly sorted if name.startswith(“step”): yield name, getattr(self, name) def test_steps(self): for name, step in self._steps(): try: step() except Exception as e: …

Read more

How to write XML declaration using xml.etree.ElementTree

I am surprised to find that there doesn’t seem to be a way with ElementTree.tostring(). You can however use ElementTree.ElementTree.write() to write your XML document to a fake file: from io import BytesIO from xml.etree import ElementTree as ET document = ET.Element(‘outer’) node = ET.SubElement(document, ‘inner’) et = ET.ElementTree(document) f = BytesIO() et.write(f, encoding=’utf-8′, xml_declaration=True) …

Read more

How to qcut with non unique bin edges?

The problem is that pandas.qcut chooses the bins/quantiles so that each one has the same number of records, but all records with the same value must stay in the same bin/quantile (this behaviour is in accordance with the statistical definition of quantile). The solutions are: 1 – Use pandas >= 0.20.0 that has this fix. …

Read more

Flask to return image stored in database

Create a response object with the data and then set the content type header. Set the content disposition header to attachment if you want the browser to save the file instead of displaying it. @app.route(‘/images/<int:pid>.jpg’) def get_image(pid): image_binary = read_image(pid) response = make_response(image_binary) response.headers.set(‘Content-Type’, ‘image/jpeg’) response.headers.set( ‘Content-Disposition’, ‘attachment’, filename=”%s.jpg” % pid) return response Relevant: werkzeug.Headers …

Read more