Web2py hello world
Tags: python, webdev, beginners
Published: 2020-02-28 22:43:06


<a href="http://www.web2py.org/">Web2py</a> is a free and open source web application framework for <a href="https://python.org">Python</a>. 
The web2py framework was inspired by the Ruby on Rails and Django frameworks. It does a lot of things for you.

Web2py uses the model–view–controller (MVC), where 

* the view is what is presented to the user (html)
* the controller is Python code 
* the model is database stuff. 

If this is unfamiliar, don't worry about it for now.
Do you want to make a web app (hello world) with Python? Lets do it!

## Create new app

Creating a Python app with web2py is mostly click work. It's not all that hard. Register on <a href="https://www.pythonanywhere.com/?affiliate_id=00535ced">PythonAnywhere</a>, as we'll work online not on localhost for this tutorial.

First add a new web app. Click on the button "open web tab", which will take you to the next screen. 

![open web tab](https://dev-to-uploads.s3.amazonaws.com/i/79vy8mxhprfbywpkz95x.png)

Then click add a new web app. Your web apps will be shown on the right, if you have created some before.

![add a new web app](https://dev-to-uploads.s3.amazonaws.com/i/b1vh7wprmyfw3fns7sga.png)

Select web2py from the list. These are all Python web frameworks you can choose from. Any is possible, but this tutorial focuses on web2py

![web2py framework](https://dev-to-uploads.s3.amazonaws.com/i/f076ylzonkauclgljotg.png)

Then the directory is already defined, add an admin password. You may want to add a challenging password, because the whole admin panel is online.

![add password](https://dev-to-uploads.s3.amazonaws.com/i/f04f79gun2pcrz40ths7.png)

That easy! Now you have a web2py web app online. It even has an admin menu (think like wordpress admin, if you're familiar with that. But here we can type Python code)

Then you are at the web-admin admin screen

![admin screen](https://dev-to-uploads.s3.amazonaws.com/i/c7ayt4a0ifmlafo1esxf.png)

## Create hello world

Click on the blue admin button and login (your app has an admin panel). This takes you to the admin dashboard

![click admin login](https://dev-to-uploads.s3.amazonaws.com/i/wd28z0tgeu363jfk3yu5.png)

In this dashboard you can add apps (your web2py app can have apps)
Add a new app (on the right). It can be called "helloworld"

![add new app](https://dev-to-uploads.s3.amazonaws.com/i/82da81jgtaptmzvsro05.png)

You'll then have a hello world app in the admin menu

![add hello world app](https://dev-to-uploads.s3.amazonaws.com/i/7mc0bi5zhrn5yc34edos.png)

Then you'll see your apps structure. It has the model-view-controller architecture. There are many files, each grouped in one of these 3 directories.

![app folder](https://dev-to-uploads.s3.amazonaws.com/i/nnbo127sg94l6zvxf0sc.png)

This comes with an online IDE. You can open the default controller, where you can change the yellow popup message. In every controller, app logic is dealt with.  This will be where your Python code resides. 

![ide](https://dev-to-uploads.s3.amazonaws.com/i/2cfa7gcsntysf0fzh6tk.png)

But because we only want a "hello world" message, no code is required.

What is shown to the user is called a view. Open the view default/index.html

You can remove everything and just put "hello world". We don't need the hypertext markup language for displaying a message (unless you want to add an image or formatting)

![template](https://dev-to-uploads.s3.amazonaws.com/i/tug5381hea2cfun5j5kh.png)

Open your apps url and you'll see "hello world".

![hello world in web2py](https://dev-to-uploads.s3.amazonaws.com/i/zpwt9fenze7wosf0at2c.png)