10 Learning Flask: Your first web application

 

In this chapter

  • Erik creates his first simple web application
  • Simon explains how Flask works (and what it is)
  • Emily and Erik work on a web form
  • The first coffee shop web-based menu is ready!

"You said you wanted to create a web application?" Simon asked Erik the other day.

"Yes, sure!" Erik said. "Otherwise how could I use my program on my iPad?"

"Okay, but be prepared: it’s not an easy task. It will require all your attention. Maybe you won’t completely understand everything we do here. But not to worry, I’ll help you when you need it."

"I know, you are a good brother," Erik said and there was almost no irony in the way he said it.

"We will use our good friend Mu Editor for our web application. It has a special mode for that. Start the editor and click Mode in the top-left corner."

Erik did and saw this menu:

Change mode

"Scroll to the bottom," Simon said. "Find the Web mode and click it. Then click Ok."

Web mode

After Erik did that, Simon pointed to the bottom-right corner and said: "See this word 'Web' next to the cogwheel? We switched to the Web mode. Now let’s see what we can do with it. Click New."

Erik did and immediately Python code appeared in the editor window.

New web app

"Interesting," he said. "Mu already wrote something for me. Can I run it?"

"Sure, go ahead. First you’ll have to save it. Call it 'first_app.py'."

Erik clicked Run, entered 'first_app.py' in the Save dialog and saw this output at the bottom of the window.

Run web app

"What is it?" he asked.

New things you have learned today

Code for this chapter

sitemap