Krishnang K Dalal Krishnang K Dalal - 1 year ago 151
Python Question

Python Flask not rendering template

I have a simple trial code for building a web page using Python Flask but somehow it is not working. The code is as following:

app.py

from flask import Flask, request, render_template
from square import Square

app = Flask(__name__)

@app.route('/first_page')
def first_page():
return render_template('first_page.html')

if __name__ == '__main__':
app.run(debug=True)


first_page.html

<!doctype html>
<html>
<body>
<h1>Hello Wold!</h1>
<h2>Welcome Here</h2>
</body>
</html>


when I run the app.py from the Spyder console and go on to Google Chrome and enter
localhost:5000/first_page
, Chrome doesn't load the page.

When I run app.py using windows command promt, it throws following error:

* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger pin code: 294-294-951
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Users\kdalal\AppData\Local\Continuum\Anaconda3\lib\threading.py", line 916, in _bootstrap_inner self.run()
File "C:\Users\kdalal\AppData\Local\Continuum\Anaconda3\lib\threading.py", line 864, in run self._target(*self._args, **self._kwargs)
File "C:\Users\kdalal\AppData\Local\Continuum\Anaconda3\lib\site-packages\werkzeug\serving.py", line 670, in inner fd=fd)
File "C:\Users\kdalal\AppData\Local\Continuum\Anaconda3\lib\site-packages\werkzeug\serving.py", line 564, in make_server passthrough_errors, ssl_context, fd=fd)
File "C:\Users\kdalal\AppData\Local\Continuum\Anaconda3\lib\site-packages\werkzeug\serving.py", line 474, in __init__ socket.SOCK_STREAM)
File "C:\Users\kdalal\AppData\Local\Continuum\Anaconda3\lib\socket.py", line 460, in fromfd nfd = dup(fd)
OSError: [WinError 10038] An operation was attempted on something that is not a socket


Please suggest me what is an issue here. Thank you.

P.S: My 'first_page.html' is under templates folder

Answer Source

This issue was fixed in Flask 0.12.1 (werkzeug 0.12.1, to be more precise).

Use the latest version, you'll be fine.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download