If your are interested in web development, you’ve heard MVC. I’m still developing web but I’ve never used MVC so I always wonder ­čÖé When I wanted to investigate, I would that there is an example that is hello word for MVC. Hear, “Hello Word Example”…

We will use Python 3.x and Bottle Framework in this article. I guess, using these is the easiest way for creating a MVC project.

If you don’t like reading, you can watch this video series. After you watched third video (“Intro to Templates”), you should read section 2 of my article.


  1. Python 2.x or 3.x (recommended)
  2. Bottle Framework (Installation)
How to Create a MVC Project Step by Step…

Select a Template For Project: Actually, we don’t have to this step, we can write a new template. But, I want to show you something in section two of article about pages that contains static files like javascript, css, img files.

1. Pages that not contain static files:

Project Directory

  • hello_world.py
  • views
    • index_basic.tpl

Your directory tree of project must be like above and your codes must be like the following.

1.1. We design a page with variables that their values will sent from python code. For this code, ‘title’ and ‘animals’ are will sent from python code.

  %for animal in animals:      
  % end

1.2. Our python code send value of variables to tpl file and run the web server.

from bottle import route, run, template

def index():
    return template('index_basic', title="Merhaba D├╝nya",animals=animals)

run(host='localhost', port=8080, debug=True)

After we run the python code, here the output:

Basic of MVC is finished.

2. Pages that include static files:

If we want to use a template that we saw before and we liked. We know, templates contains multi files like html, js, css, img files. If we just change the extension html to tpl, our output will be too bad like as in dreams/in reality ­čśÇ

In Dreams ­čśÇ


In Reality ­čśÇ

If we want to see the page as in dreams, we must add something to the python code. We saw the page too bad because our get requests for js, css files returned with 404 code. Bottle web server didn’t understand path of files. We must tell them to python.


You know we are running with tpl files now. And we said to python the tpl file that be shown but we didn’t said to python the files and paths that be included. Python is just showing tpl file but it doesn’t know what to do if there is a get request.

2.1. Design a Template File


    <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="css/4-col-portfolio.css" rel="stylesheet">

2.2. Write the Python Code

from bottle import route, run, template, static_file

def serve_static(filename):
    return static_file(filename, root="./views/vendor/")

def serve_static(filename):
    return static_file(filename, root="./views/css/")

def index():
    lists=["First Aritcle","Python and Bottle","Test Article","You Like It","Example Article","Hi! I'm a Researcher","This Post For You"]
    return template('index', title="Hello World from Bottle", titleOfArticle=lists)

run(host='localhost', port=8080, debug=True)

So the python code will understand the paths and the output will be regular.

You can download project from this link.

For more informations.