Skip to content

Introduction to the API Example Project#

2024 iThome Ironman

This is the 4th article in the Django Ninja tutorial series.

In Chapter 1, we provided a comprehensive introduction to Django Ninja and analyzed its main differences from Django REST framework.

I believe you already have a basic understanding of Django Ninja.

Next, we will enter Chapter 2: Project Introduction and Setup.


Focus of This Chapter#

We will help you apply the concepts of Django Ninja in practice through a CRUD API example project.

This chapter introduces the project concept, including the model design and its real-world counterparts (Article 4).

It then covers the Python development tools used in the project (Article 5). Finally, we will guide you through installing the project locally and making sure it runs correctly (Article 6).

The rest of the code regarding the API will be introduced and implemented sequentially in Chapter 3.

GitHub Example Project#

👉 Django-Ninja-Tutorial


Ninja Forum#

To help you better understand Django Ninja and perform hands-on operations, we have designed an example project—Ninja Forum.

This is a discussion board for developers to exchange experiences using Django Ninja (rather than how to become a ninja).

Welcome to Ninja Forum

This is the GitHub URL of the project. You can bookmark it to refer to the code anytime and deepen your learning impression.

This project demonstrates how to build APIs with Django Ninja, putting the concepts and practices from this series into action.


Design Philosophy#

The theme of the project is "Ninja Forum," which is a basic discussion board system featuring core functions that allow users to publish posts and leave comments.

This design is both simple and practical, allowing you to focus on the core of Django Ninja without being distracted by too many extra features.

The two basic functions of the forum are also the focus of our API implementation:

  • User System: Users can register, log in, log out, and view their own posts.
  • Posting System: Users can create, modify, and delete posts.

Through this project, you will learn how to quickly build related APIs using Django Ninja.

We will focus on posts and implement different APIs step by step.


Three Design Principles#

As an example project, Ninja Forum is designed to give you a deeper understanding of Django Ninja's basic concepts and applications through hands-on practice.

Therefore, we will strictly limit the project content within the scope required for teaching to ensure focused learning without being disturbed by excessive details.

In short, the project follows the three design principles below.


I. Minimalist Design Principle#

Here, "minimalist design" means making sure that nearly every implementation serves a teaching purpose.

We will even reuse the same API as an example to demonstrate feature implementations at different stages.

This design keeps the teaching content concise while gradually delving deeper into various features of Django Ninja.


II. Simple and Clear Code Structure#

The code structure of the example project should be simple and clear, allowing readers to quickly grasp the logic and relationships of each part.

Compared to real-world work projects, the example project focuses more on code clarity and readability at a glance, avoiding unnecessary complex designs or abstraction layers.

This means:

  • We will not introduce excessive component splitting or modular design, but present the features directly.
  • The implementation of each feature is kept as simple as possible, focusing on how to implement it.

This design enables you to quickly understand the role of each code snippet and easily apply it to your own projects.


III. Easy-to-Use Environment#

The example project needs an easy-to-use environment that allows learners to immediately run the project and test what they have learned.

Work projects involve many external dependencies, but the design of the example project focuses on allowing learners to quickly validate the concepts they have learned.

This means:

  • The project does not require a full deployment; a small amount of local configuration is enough to run and test it, so readers can see API responses immediately.

We focus strictly on the API tutorial itself; you may need to explore and fill in other integrations and steps on your own.


Next Steps#

After understanding the design of the example project, we will enter the development environment introduction.

When developing a project, appropriate tools can make the work much more efficient. The next article will introduce commonly used Python development tools, such as virtual environment management and code formatting.

These tools not only help you manage projects efficiently but also significantly improve the quality and consistency of your code. I believe that mastering these tools proficiently is a basic skill for modern developers.