Joke Collection Website - Public benefit messages - How to develop an api with python?

How to develop an api with python?

During the Spring Festival last year, I signed up for the online course of pythonweb development and answered according to my own learning situation. The development of a page should be divided into front end and back end. There are two most common back-end development frameworks in python: Django and flask. Django is big and complete, and all the functional modules have been packaged and can be called. Flask is small and exquisite, without high packaging, but there are many functional modules that need to be integrated by themselves.

The online course I studied at the beginning was done with flask framework, and it was easy to get started: I would write a small website when I was studying, and I wanted to switch to python back-end development, and then I went to do data mining, but it didn't take long and I was a little rusty. Generally speaking, there are several modules: route () decorator binds a function to the corresponding URL, and Flask's URL rule is a routing module based on Werkzeug.

The idea behind this module is based on the precedent advocated by Apache and early HTTP servers to ensure elegant and unique URL. Template rendering Jinja2 Generating HTML in Python is very boring, because you have to escape the HTML manually to ensure the security of the application. To this end, Flask is equipped with a Jinja2 template engine.

Of course, other template engines can also be used, but it is recommended to use jinja2 template to request objects. You can use the global request object to access incoming request data. Flask processes incoming request data and allows you to access it using this global object. If you work in a multithreaded environment, Flask internally guarantees that you will always get the correct data on the current thread.

Database interaction -Flask-SQLAlchemy adds, deletes, modifies and queries the database through SQLAlchemy, and uses orm mode without writing SQL statements. In a database, a table is a python class, and an instance of the class is a row in the table. In the development process, some advanced applications of python will be used: decorator: module import is very necessary for permission verification; Prevent image processing from being imported circularly; Using verification code to generate attributes: About front-end using password encryption. If you are not familiar with the front end, you want to be a small website trainer. I recommend you to use Bootstrap, which contains various CSS styles, various components, JS plug-ins, and some website examples for your reference. You are not familiar with front-end HTML and CSS.

Postscript: Future data mining workers may also need to understand the back-end development of the website, because future modeling will not always be in a stand-alone machine, but may be integrated into the website, and real-time data will flow into the model and the results will be displayed on the website.