The most popular web development frameworks for Python are Django, Flask, and Tornado.
Django can be said to be the framework with the most complete ecosystem. Developing with Django can even feel like learning a new language.
I have also tried Flask before. It is small and flexible, but there are too many details for programmers to consider, which can be a burden.
I have had less exposure to Tornado. It is an asynchronous framework, and from what I know, it is mainly used in the Jupyter ecosystem.
Environment Setup and Creating a New Project#
I won't go into detail about setting up the Django environment, you can search for it yourself.
This time, we are going to develop a check-in system, with main features including publishing learning content, student management, creating study plans, and student check-ins.
Let's name the project "easy_talk". We will use Django to implement the backend. First, create a new project.
django-admin startproject easy_talk_backend
Now we have created a Django project. After entering the
./easy_talk_backend directory, let's create an app.
In Django, an app is a way to organize code. Each Django project can consist of multiple apps, with each app responsible for handling specific functionalities in the project. Typically, an app includes the following:
- models.py: Defines the data models for the app.
- views.py: Handles user requests and returns responses.
- urls.py: Defines the URL configurations for the app.
- templates/: Stores HTML templates.
Using apps makes the code easier to organize, maintain, and reuse. Multiple apps can be easily combined into a larger project.
Let's create an app called "study".
python manage.py startapp study
./easy_talk_backend/study directory contains the code for this app, including URLs, views, models, and HTML files.
We need to modify
./easy_talk_backend/settings.py to register our app.
INSTALLED_APPS = [
By default, Django uses SQLite to store data. We won't make any changes and will directly run the following command to initialize the database.
python manage.py makemigrations
python manage.py migrate
Let's create a superuser.
python manage.py createsuperuser
Now, let's run our project.
python manage.py runserver
You should be able to see the default Django homepage. Accessing the
/admin route will allow you to log in to the Django admin panel using the user and password we just created.