首頁 >常見問題 >2024 年選擇 Django 的 5 個理由

2024 年選擇 Django 的 5 個理由

百草
百草原創
2024-04-09 14:11:201167瀏覽

Django是一款相當年代的Python框架,但憑藉其快速的開發速度和低廉的成本,它在2024年仍然值得考慮。 Django擁有豐富的功能,涵蓋了從SQL資料庫管理到API服務,並且可以輕鬆部署到無伺服器架構中。其強大的Python語言支援以及龐大的社區,使其成為各種小型專案的理想選擇。

2024 年選擇 Django 的 5 個理由

決定採用全端技術是令人畏懼的。有大量的框架需要評估。 

我將分享我的逆向觀點。選擇姜戈。 Django Python 框架很舊,但它可以快速且廉價地完成工作。 Django 有一種「包羅萬象、固執己見」的哲學。這種方法使得 Django 的上手速度非常快。隨著專案規模的擴大,將 Django 分成單獨的元件,這些元件可以用作 SQL 資料庫管理器、物件關聯映射器或 API 伺服器。

2024 年,我們停止在後端使用 Firebase 和 MongoDB,轉而使用 Django。雖然許多專案可以從更現代的框架中受益,但選擇更新的技術也可能會導致更多的成本,因為團隊很難找到具有所需技能的開發人員,並且後來發現隨著不可預見的問題的出現,開發預算不斷增加。有了 Django,您之前的開發道路已經由數以萬計的開發人員順利鋪好。  

對於我們為業務工作流程建置的小型專案類型,Django 不僅可以更快地將想法引入原型,而且建置和維護成本也更低。以下是 2024 年應考慮使用 Django 的 5 大理由。

1. SQL 即服務

Django 使用SQL 資料庫。與 Django 一樣,SQL 被認為是古老的,並且不如 MongoDB 等較新的 NoSQL 資料庫那麼迷人。查看 Django 的一種方法是將其視為具有預先建置程式碼的 SQL 資料庫,以使資料庫更易於使用。如果 Django 無法滿足您未來對特定功能的需求,您仍然可以單獨使用 SQL 資料庫,或者使用 Django 的部分內容來使資料庫更易於存取。  

 在我們的範例中,我們的 Django 部署的一部分由託管的 PostgreSQL 資料庫作為服務組成。首先,我們只需將連接資訊新增至 Django 應用程式即可。這種架構還允許我們使用 Django 作為臨時原型工具來設定資料的工作介面和邏輯。隨著專案的發展,我們可以繞過 Django,使用 Flutter 或 React 等其他應用程式直接連接資料庫,或設定精簡的中間伺服器來橋接資料庫和前端。 

SQL的成熟度在招募人才時也是優勢。許多大學和技術學校都將 SQL 作為主流課程的一部分。從學校招募人才更容易,因為學生擁有最近的學術經驗並渴望獲得更多的現實經驗。大多數商業軟體專案無需高級 SQL 資料庫管理技能即可完成。 

2.API服務

使用 SQL 或Django REST 框架公開 API 端點的能力使我們能夠使用不同的技術快速建立多個資料庫介面。儘管 Django 模板易於學習且功能強大,但這些模板的互動性不如反應性更強的框架。  

幸運的是,Django 可以為相同的資料提供 Django 頁面模板和 REST API。這意味著您可以測試不同的前端架構,同時重複使用後端的大部分核心邏輯。

從 Django 而不是 API 伺服器開始的好處是更容易開始使用 Django 和原型化概念。 Django 非常容易安裝,並且配備了 Web 應用程式所需的一切。 pip install django會讓你繼續前進。建立功能原型並部署它的速度非常快。 Django 附帶身份驗證、資料庫、開發 Web 伺服器和模板語法。這使得可以使用不同的安全群組和內建的員工管理面板來快速建立複雜的網站。 

3. 無伺服器架構

Django 可以輕鬆部署到無伺服器架構,並消除虛擬伺服器的設定和維護。從 2023 年開始,我們將 Django 專案遷移到無伺服器架構。之前,我們在虛擬伺服器中使用Ubuntu Linux。我們曾經在同一個可擴充虛擬伺服器中運行 PostgreSQL、NGINX 和 Django。遷移到一套資料庫、儲存、CPU 和網路雲端服務後,啟動一個新專案只花了不到一天的時間。 

在軟體開發過程中,我們的程式碼被推送到分支上的 GitHub,我們可以在瀏覽器中將其作為 Web 應用程式進行預覽。在同行或經理審查拉取請求後,它會合併到主分支中,觸發將程式碼自動部署到生產服務以運行應用程式。 Django 的 GitHub 部署腳本以及設定由應用程式服務提供。我們只是複製並部署它。 

Since our application service cannot be used to store media and data, we use different services to store media such as images. Since Django has been around for so long, there will be a solution for almost every connection problem you encounter. For example, the AWS SDK Boto3 for Python provides easy access to S3, which is how we handle storage.

4.Python

Python remains one of the most popular languages. It is widely taught at all levels of education in the United States, including elementary, middle school, high school, and college. Such a large talent pool makes recruiting easier, and integrating Python into structured academic courses can lead to better programming practices. Even if you have no experience with Python, someone familiar with another language can quickly become more productive.

Since no compilation is required, Python facilitates a very fast development workflow. The lack of compilation does take a performance hit. For most projects, hardware is cheaper than labor. With a scalable cloud-based architecture, Django's performance is never an issue for projects with low concurrent connections.

Although Python is dynamically typed, you can use types to take advantage of type hints.

Perhaps more important than language features is the tool chain. Since Python does not require compilation, the toolchain is easier to set up and maintain. Lightweight tools like pyenv and venv can keep Python and package versions consistent across your entire development team. As long as PATH is set correctly on the developer workstation, development and deployment usually go without problems. Our team develops on a mix of Windows 10, Windows 11, macOS, and Ubuntu 22.04. Although not required, everyone uses VS Code with a range of Python extensions.

5. Community

More than 20 years have passed, and almost all Django problems have been solved by others.

The community’s sheer size and long history also contribute to personnel changes. Most information about Django can be found by searching the QA website or the AI ​​website.

In contrast, when I used other newer frameworks, I found that I needed to get information by asking people questions, usually on systems like Discord or Slack.

With Django, I usually don't have to wait for someone to answer my question because tens of thousands of Django developers before me have usually asked and answered the question. Although there are many free and cheap courses on Django and Python, most people just start coding and looking for answers.

While both the Python language and Django are under active development, most problems in small projects do not occur due to edge cases in the language or framework.

The future development of Django

I will not predict the future. Young people will create it. At my company, we have an active undergraduate internship program. Of course, they use and love Django. However, this is part of their job. It amazes me that they use Python and Django in their own projects outside of work. I typically expect people under 24 years old to use JavaScript, and possibly TypeScript, on both the backend and frontend of full-stack projects. Young programmers are the future, often using Python for the backend combined with things like Django admin panel, Django template syntax, and React for the frontend.

Ultimately, a more modern framework may be better suited for your project. If you like Python, then Flask or FastAPI are probably better than Django. GraphQL with Django is probably better than the tried and true REST protocol. However, before you think Django is old and monolithic, take a fresh look at it from a componentization perspective. This is probably the fastest and cheapest way to bring your idea to life.

20 years later, Django is still doing great.

以上是2024 年選擇 Django 的 5 個理由的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn