Python Tutorial: Creating Your First Web Page and Understanding Routing (Route)

![[Python 강좌] Python Flask 블로그 만들기, 지금부터 함께 시작합니다.](/uploads/editor/Python-%EA%B0%95%EC%A2%8C-Python-Flask-%EB%B8%94%EB%A1%9C%EA%B7%B8-%EB%A7%8C%EB%93%A4%EA%B8%B0-%EC%A7%80%EA%B8%88%EB%B6%80%ED%84%B0-%ED%95%A8%EA%BB%98-%EC%8B%9C%EC%9E%91%ED%95%A9%EB%8B%88%EB%8B%A4-20260706-614807.webp)
Create Your First Web Page
In the previous lesson, we set up a Python and Flask development environment.
Now it's time to write actual code to create a web page.
We'll start with a simple screen that will serve as the foundation for your future blog.
Web development doesn't begin with complex features—it starts with creating one page and gradually adding functionality.
Starting Your Flask Program
If you've created an app.py file in your project folder, write the following code:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def home():
return "Welcome to your Flask blog."
if __name__ == "__main__":
app.run(debug=True)
The code may not look long, but it contains all the essential elements needed to run a Flask web program.
Understanding the Code
First, this line imports Flask functionality:
from flask import Flask
In Python, we use import to access features created by others.
This line imports the Flask class from the Flask library.
The next part creates the Flask program:
app = Flask(__name__)
Here, app represents the website we're building.
All pages will be managed through this app object.
What Is Routing (Route)?
The most important concept in this lesson is routing (Route).
Routing determines which page to display when a user visits a specific URL address.
For example, consider the following address:
/
This address represents the homepage of your website.
In Flask, you would write it like this:
@app.route("/")
def home():
return "Welcome."
This means:
When a user visits the
/address, execute thehome()function.
Create Multiple Pages Easily
Routing isn't limited to just one page.
You can add as many pages as you want.
For example, an about page would look like this:
@app.route("/about")
def about():
return "This is the About page."
You could also create a notice page:
@app.route("/notice")
def notice():
return "This is the Notice page."
Each URL can be linked to a different function, displaying your desired screen.
Run Your Program in a Web Browser
Now let's run the program.
Enter this command in the terminal:
python app.py
If it runs successfully, you'll see a message like this:
Running on http://127.0.0.1:5000
Type this address into your web browser, and you'll see the text we wrote:
Welcome to your Flask blog.
This is when your custom program appears in a web browser for the first time.
What Does debug=True Mean?
At the end of the program, you'll see this code:
app.run(debug=True)
The debug=True setting is very useful during development.
Its benefits include:
Automatic restart after saving code changes.
Clear error messages when issues occur.
Significantly faster development process.
However, for production environments, you must change it to debug=False for security reasons.
How Your Blog Will Expand
While we've created just one page now, we'll gradually add more features.
For example, you might create pages like these:
/
/login
/write
/post/1
/post/2
/search
/admin
All of these pages will be connected using the routing (Route) concept we learned today.
In other words, this lesson's content forms the foundation for all future features in your blog.
Understanding Routing Reveals Website Structure
Websites consist of many pages.
Each page has a specific URL, and the website executes corresponding functionality based on that address.
To help understand this, consider this simple mapping:
URL Address | Function Executed |
|---|---|
/ | Main page |
/login | Login |
/write | Write a post |
/list | List of posts |
/post/1 | View specific post |
This URL-function connection is exactly what routing (Route) means.
Key Takeaways from This Lesson
In this lesson, we learned the most important concept in Flask development:
Creating a Flask program
The role of
app.pyHow to use
@app.route()Connecting URLs with functions
Running the program in a web browser
The meaning of
debug=True
Understanding these basics will make it much easier to build your blog's structure.
In Conclusion
Today, we created our first web page using Flask and learned about the most important concept in web development: routing (Route).
While this seems like a simple program that outputs one line of text, it's the foundation for adding HTML templates, connecting to databases, creating writing features, and eventually building a complete blog.
In our next lesson, we'll learn how to use HTML templates (Jinja2) instead of just printing strings to create actual website layouts.
FAQ
What is routing in web development?
Routing determines which page or functionality loads when a user visits a specific URL address.
Why use debug=True during development?
It automatically restarts the app after code changes and provides detailed error messages, speeding up development.
Korean Source
This article is an English localization of a Korean-language report from BlogScore. Original: [Python 강좌] 3강. 첫 번째 페이지 만들기와 라우팅(Route) 이해하기