<commit_before>---
topic: "Webapps Intro, Part 2"
desc: "ftoc (from url), and intro to templates"
---

In part 2 of the SPIS 2016 webapps tutorial, we'll learn about how to:

* Perform a calculation based on a parameter that's in the url
* Start building a larger multi-page web application

## Keeping your ACMS Account Safe: turn debug mode off.

So, trying to teach web development in an academic computing environment such as ACMS is always a bit of a risk.   The basic problem is this combination of things:

* Web servers, by their very nature while under development, can contain security vulnerabilities
* Because of this, web developers typically test web apps on systems that "have one job", i.e. to test a web app, 
    and are used by "only one user", the one doing the web app development.
* But, in an academic computing environment, it is typical for many students, (i.e. many users), to all be running on the      same system.
* Hence, the problem.

This is not a show-stopper of a problem.  There are some reasonable things you can do to mitigate the risk.   You should definitely do these things. 

To use Flask safely on ACMS, do NOT enable debug mode:

```python
app.run(port=5000,debug=True)  # DO NOT do this on your ACMS ACCOUNT
```

If you do set `debug=True`, that allows anyone that can bring up your web app to execute any line of Python code they want, but as you, in your account.  That means they could launch a spambot, delete all your files, or do something even more awful.

```
app.run(port=5000,debug=False)   # ALWAYS DO THIS when  RUNNING ON ACMS, THIS IS THE SAFE THING TO DO
```
This is the safe thing to do when running on ACMS.

Note that debug mode is really useful, but if you want to be able to use it, you'll need to invest the time in installing Python on your own personal computer (laptop or desktop) and then running Flask there.   That's the only safe environment to turn debug mode on—when you can be totally sure that no-one but you can get to the web browser where debug mode is enabled.

# Our next step with Flask: actually computing something

Ok, a web page that prints "Hello World" is not really very compelling.  Let's do something a bit more interesting.

## Add an ftoc function to hello.py

We've already seen a function that converts Farenheit to Celsius.  Let's add this to our hello.py file, so that we have the following:<commit_msg>Update webapps-intro-part-2.md<commit_after>---
topic: "Webapps Intro, Part 2"
desc: "ftoc (from url), and intro to templates"
---

In part 2 of the SPIS 2016 webapps tutorial, we'll learn about how to:

* Perform a calculation based on a parameter that's in the url
* Start building a larger multi-page web application

## Keeping your ACMS Account Safe: turn debug mode off.

So, trying to teach web development in an academic computing environment such as ACMS is always a bit of a risk.   The basic problem is this combination of things:

* Web servers, by their very nature while under development, can contain security vulnerabilities
* Because of this, web developers typically test web apps on systems that "have one job", i.e. to test a web app, 
    and are used by "only one user", the one doing the web app development.
* But, in an academic computing environment, it is typical for many students, (i.e. many users), to all be running on the      same system.
* Hence, the problem.

This is not a show-stopper of a problem.  There are some reasonable things you can do to mitigate the risk.   You should definitely do these things. 

To use Flask safely on ACMS, do NOT enable debug mode:

```python
app.run(port=5000,debug=True)  # DO NOT do this on your ACMS ACCOUNT
```

If you do set `debug=True`, that allows anyone that can bring up your web app to execute any line of Python code they want, but as you, in your account.  That means they could launch a spambot, delete all your files, or do something even more awful.

```python
app.run(port=5000,debug=False)   # ALWAYS DO THIS when  RUNNING ON ACMS, THIS IS THE SAFE THING TO DO
```
This is the safe thing to do when running on ACMS.

Note that debug mode is really useful, but if you want to be able to use it, you'll need to invest the time in installing Python on your own personal computer (laptop or desktop) and then running Flask there.   That's the only safe environment to turn debug mode on—when you can be totally sure that no-one but you can get to the web browser where debug mode is enabled.

# Our next step with Flask: actually computing something

Ok, a web page that prints "Hello World" is not really very compelling.  Let's do something a bit more interesting.

## Add an ftoc function to hello.py

We've already seen a function that converts Farenheit to Celsius.  Let's add this to our hello.py file, so that we have the following:
{'fraction_non_alphanumeric': 0.05556707443499896, 'fraction_numerical': 0.006012855069458843, 'mean_word_length': 3.882591093117409, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3375222', 'n_tokens_mistral': 1331, 'n_tokens_neox': 1263, 'n_words': 809}