Flask is a lightweight WSGI web application framework. It is designed to make getting started quick and easy, with the ability to scale up to complex applications.
Its one of the most popular Python web application frameworks.
It doesn’t enforce any dependencies or project layout
It is up to the developer to choose the tools and libraries they want to use.
There are many extensions provided by the community that make adding new functionality easy.
pip install -U Flask
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return 'Hello, World!'
@app.route('/')
def Index():
return render_template('index.html')
@app.route('/response',methods = ['POST', 'GET'])
def result():
if request.method == 'POST':
out_dict = {}
result = request.form
url = result['URL']
response_type = result['response_type']
response = requests.get(url, verify=False,headers ={'User-Agent': get_user_agent()}).content
img_obj = PIL.Image.open(BytesIO(response))
out_dict.update(image_analysis(img_obj,response))
if str(response_type).lower() == "json": return json.dumps(out_dict)
else: return render_template("response.html",result = out_dict)
if __name__ == "__main__":
app.run()
index.html
<form action = "http://127.0.0.1:5000/response" method = "POST">
<center><h4>URL      : <input type ="text" size='50' name = "URL" /></h4></center>
<center><h4>RS Type : <input type ="text" size='50' name = "response_type" data-tip="json"/></h4></center>
<p><center>            nbsp<input type = "submit" value = "Extract" size="70"/></center>
</form>
Response.html
<table border = 1>
{% for key, value in result.items() %}
<tr>
<th align="Left"> {{ key }} </th>
<td> {{ value }} </td>
</tr>
{% endfor %}
</table>