Finalizing the Web Application
00:00 The Final Web App. The web app you’re creating uses only one URL endpoint, and because of this, you can’t rely on Flask to type check the user input via URL path component capturing as you did earlier on.
As a result of this, a number of changes will be made to the code.
escape() will no longer be needed as the input validation will be part of that
fahrenheit_from() function, so it will no longer be imported and will be removed from the line where the
celsius key is read from the global
index will have a conditional statement added to check the value of
If it has a value, then you will call
fahrenheit_from() to calculate the corresponding Fahrenheit degrees. If it’s an empty string, then you assign an empty string to the
fahrenheit variable instead.
fahrenheit_from() will no longer be associated with the URL endpoint, so the decorator will be removed.
fahrenheit_from() will also have the
except block reintroduced to allow for type checking.
As before, you’re fetching the user-submitted value through Flask’s global
request object. By using the dictionary method
.get(), you assure that an empty string gets returned if the key isn’t found. That’ll be the case if the page is loaded initially and the user hasn’t submitted the form yet.
fahrenheit_from() will no longer be accessible via a URL endpoint, so the decorator is removed. The
except block is reinstated so that if a non-numeric value is entered, the function will now return an appropriate error message as text to be displayed to the user.
03:23 You can supply a Celsius temperature through the input box, click the button, and see the converted Fahrenheit result appear on the same web page. Since you’re using the default HTTP GET request, you can also see the submitted data appear in the URL.
In fact, you can even circumvent the form and provide your own value for
celsius by supplying an appropriate address, similar to how you were able to use the conversion when you built the script without the HTML form.
04:33 Test it out by adding different types of input. Once you’re satisfied, you can share your link with the world. At this point, you’ve successfully converted your Python script into a Python web app and deployed it to Google App Engine for online hosting.
Become a Member to join the conversation.