A complete guide to Python web development

Blog: https://somenzz.cn, computer reading is more convenient, you can visit the link in the article to read the original text.

After learning Python for so long, I finally feel that programming language is just a tool. If we want to realize our own value through technology, we cannot do without specific application scenarios. There are many application scenarios, and our time and energy are limited. Maybe you can learn everything, you must make a choice, just like choosing a hero's profession when playing a game, whether it is a mage or a jungler, you can only choose one. Once you choose, you cannot change it until the game is over.

It's the same with programming. Choose a direction, study hard, go deep, and don't change easily. For Python, there are five main application areas, automated testing or operation and maintenance, crawling, data analysis, web development, machine learning or artificial intelligence. The difficulty of getting started in these fields ranges from automation to machine learning from easy to difficult. Especially for machine learning, the requirements for Python are not high, but mathematics and algorithms must be proficient.

I believe that everyone has their own career choice. Today I will share a complete guide to using Python to engage in web development. The main contents are as follows:

  1. What is web development? 2. Why is Python suitable for web development? 3. What are the popular Python web frameworks? 4. What are the Python libraries for web development? 5. Web development learning roadmap 6. Create the first web application with Python 7. Become a Python web developer

**1、 What is website development? **

For those who are new to programming, you may want to know what Web development is. Although it is impossible to pinpoint an exact term, Web development can be roughly defined as building, creating, and maintaining a website. Generally, Web development involves a front end, everything that interacts with the client, and a back end that contains business logic and interacts with the database. The front end involves html, css, javascript, and derived libraries and frameworks, such as Angular, React, and Vue. It can be described as endless. The backend can be implemented in many languages, here is Python, and there are also very rich frameworks, which will be mentioned later.

**2、 Why is Python suitable for web development? **

One is easy to learn: Python is the most popular language for beginners. Compared with other languages such as Java and C++, you can write less code, reduce errors, and improve efficiency. Not only that, it also has a lower barrier to entry, because it is relatively more similar to everyday language and can easily understand the code.

The second is that it has a rich ecosystem and libraries: Python provides a wide range of library tools and packages, which can access many pre-written codes, thereby reducing application development time. For example, you can use Numpy and Pandas for mathematical analysis, Pygal for graph analysis, and SLQALchemy for combinable queries. Python also provides amazing web frameworks, such as Django and Flask, which will be discussed in depth later.

The third is rapid prototyping: Compared with other programming languages, Python can save a lot of time to build projects. Your ideas can be realized faster, so you can get feedback faster and iterate faster. This efficient development makes Python particularly suitable for startups that can enter the market faster to gain a competitive advantage.

Fourth is the widespread popularity: Python is one of the most popular languages in the world, with community contributions from all over the world, and almost all technical problems can be quickly found through search engines. Python itself is constantly being updated to provide new features and libraries, as well as excellent documentation and community support. Especially for new developers, Python provides extensive support and frameworks.

**3、 What are the popular Python web frameworks? **

What is a web framework and why is it so important? Think of a web framework as a toolbox. A web framework is pre-written and consists of standardized codes. It serves to write web applications. The purpose is to make development faster and easier. The collection of packaging and modules makes web applications more reliable and easier to extend. In other words, the framework saves you from doing tedious work.

The Python Web framework is only used in the back-end for server-side technology, for URL routing, HTTP requests and responses, database access, and web security. Although it is not necessary to use a web framework, it is strongly recommended that you use it because it can help you develop more complex applications in less time.

So what are the popular Python web frameworks?

1、 Django

In order to create complex, high-quality web applications in a shorter period of time, many web developers would prefer the Django framework. Django provides an open source high-level framework that encourages rapid development and concise and practical design. It also provides strong community support and detailed documentation. Django keeps pace with the times and relatively updates its functions according to the trend of web development. The features of Django are as follows:

•Open source code•Full stack framework (one-stop service, complete solution)•Authorization•URL routing•Template engine•DRY (don't repeat yourself) design pattern•ORM mapping•Database architecture support, support [PostgreSQL] (https://cloud.tencent.com/product/postgresql?from=10680), MySQL, SQLite, Oracle•Follow the MVC design architecture

The official document is the best tutorial, you can build the first program from scratch. Django is very flexible, and you can work with MVPs from large companies. Some of the largest companies using Django are Instagram, Dropbox, Pinterest, and Spotify.

2、 Flask

Flask is considered a micro-framework, a minimalistic web framework. It is not that "battery-inclusive", which means it lacks many of the features and functions provided by a full-stack framework like Django, such as a web template engine, account authorization, and authentication. Its main features are as follows:

• A lightweight, micro-framework • Relatively low learning cost, quick entry • Support JinJa2 template engine • Modern template language after Django template language

Flask is extremely simple and lightweight, which means you can add the extensions and libraries you need as you write your code. The idea behind Flask is that it only provides the components needed to build applications, so developers have a lot of flexibility and control. Flask is also a popular and powerful web framework that has been used by major companies such as Netflix, Linkedin and Uber.

3、 Bottle

It is commonly referred to as a small micro-framework. It mainly focuses on Web API and tries to bundle everything in one document. It has no dependencies except the Python standard library. The features of Bottle are as follows:

• Micro-framework • A single source file was originally used to build the api, which means that everything is in one source file. • URL routing. • Template engine. • Utilities. • Abstraction on the WSGI standard.

Bottle is very suitable for prototyping, learning the organization of web frameworks, and building simple personal applications.

4、 CherryPy

CherryPy is a popular framework with embedded multi-chain servers, including server pool, installation framework and module framework. Its characteristics are:

• Open source minimalism • Run multiple htpp servers at once • Powerful configuration and flexible plug-in system • Built-in support for profiling, coverage and testing

5、 Pyramid

Pyramid is part of the Pylon project; it is one of the most flexible frameworks in the Python language. The framework allows developers to choose anything such as: DBMS, URL structure, template style, etc.

6、 Web2Py

Web2Py allows debuggers and code editors to edit and debug code through deployment tools. It enables developers to develop, modify, deploy and manage web applications through a web browser.

Every year there may be new frameworks or new features of existing frameworks. Which one should you use as a developer?

So far, Django is the most popular framework, followed by Flask. If you don't know how to choose, choose one of the two.

You may also ask: Should I choose Django or Flask? The answer is that it depends on the skill level of the web developer. If you are experienced, please consider using more "barebone systems" to develop programs. And if you are a junior developer, it is best to use a framework that provides more support (such as Django).

In addition, ask yourself, do you want to use the basic code base for building or do you want to build the backbone of the code base flexibly? If it is the former, please use Django; if it is the latter, please choose Flask. In the final analysis, both of them can achieve the same function, and it is more important to start coding, rather than worry about which framework is better.

**4、 What are the Python libraries for web development? **

If you need a web crawler to extract data for your application, Scrapy is very suitable. It is a widely used library for crawling, data mining, automated testing, etc.

Zappa is a powerful library for developing serverless applications on AWS Lambda.

The Requests library can easily send HTTP requests to communicate with applications and obtain HTML page data.

Another useful library is Dash, which can help develop web applications related to Data Visualization. It is built on Flask and provides functions such as charts, graphs, dashboards and more.

5、 Web Development Learning Roadmap

Step 1: Basic knowledge reserve

First of all, the three most basic front-end things HTML 5, CSS 3 and JavaScript (ES6) must be learned. There are many, many technologies, such as Canvas (bitmap), SVG (vector diagram) and WebGL (3D diagram) derived from CSS 3, as well as various graphics transformations of CSS that allow you to make very rich rendering effects. And animation effects. ES6 simply takes JavaScript to a new level. The power of JavaScript language greatly releases the productivity of front-end developers, allowing the front-end to develop more complex codes and programs.

• The core principle of JavaScript • The working principle of the browser • HTTP protocol: HTTP/2, short connection, long connection, Stream connection, WebSocket

Step 2: Front-end framework and performance tuning

Currently, the front-end community has three major frameworks: Angular.js, React.js and Vue.js. React and Vue are more powerful, and novices can start learning from Vue.

For front-end performance optimization, you can read the following books:

Web Performance in Action is a very good book, including CSS, images, fonts, JavaScript performance tuning, etc.

Designing for Performance talks about a lot of web page optimization technologies and related tools, which can give you an understanding of overall web page performance optimization.

High Performance JavaScript lets you know how to improve all aspects of performance, including code loading, running, DOM interaction, page life cycle, etc. Yahoo's front-end engineer Nicholas C. Zakas (Nicholas C. Zakas) and five other JavaScript experts introduced the best methods and programming skills for page code loading to help you write more efficient and fast code.

Step 3: Back-end skills learning

The first is the understanding of server-related protocols, such as WSGI and ASGI protocols. Secondly, the Python-related Web frameworks mentioned above also include some API frameworks, such as: Django REST Framework, FastAPI, Flask REST frameworks, etc.

In addition, you must learn database-related knowledge, SQL language, database-related query optimization is also indispensable.

Finally, learn about the relevant technologies deployed on the server, including nginx, uwsgi, gunicorn, https protocol, etc.

6、 Create your first web application in Python

Use Flask to create the first HelloWorld Web application, first install Flask.

pip install flask

Create a hello.py file and write the following:

from flask import Flask
app =Flask(__name__)

@ app.route("/")
 def hello():return"Hello World!"if __name__ =="__main__":
 app.run()

The code is very simple, so I won't explain it, execute python hello.py, and then visit http://locahost:5000/, you can see a webpage displaying "Hello World!"

7、 Choosing to be a Python Web Developer

Congratulations! You are gradually becoming a web developer proficient in Python. Now you should have a good understanding of how to use Python for web development. This kind of understanding will not be lost on the road of web development learning.

Summary

Web development in Python is mainly back-end development, and there are many options for back-end languages, such as Java and GoLang. Front-end knowledge cannot bypass html, css, and javascript, so front-end knowledge must be mastered. The back-end part can be started from Python. After proficiency, there is spare capacity to master other back-end languages.

Recommended Posts

A complete guide to Python web development
A practical guide to Python file handling
Python implements a universal web framework
Real zero basic Python development web
How to make a globe with Python
A quick introduction to Python regular expressions
What are web development frameworks in python
Build a python development environment under Ubuntu
How to sort a dictionary in python
How to convert web pages to PDF with Python
How to simulate gravity in a Python game
01. Introduction to Python
python-Use python to write a small shopping program
How to write a confession program in python
Introduction to Python
Centos8 implementation steps to build a local web server
How to understand a list of numbers in python
How to create a Python virtual environment in Ubuntu 14.04
Python implements FTP to upload files in a loop
Python web crawler (practice)
Centos 6.4 python 2.6 upgrade to 2.7
python development [first article]
Web Scraping with Python
How to find the area of a circle in python