Tips of using pycharm in backend development

Time:2020-5-20
catalog
  • Tips of using pycharm in backend development
    • 1. Instructions for use
    • 2、database
    • 3、HTTP Client

 

1. Instructions for use

First of all, the functions used in this article are supported by pycharm professional edition. Other editions, such as community edition and Education Edition, are not necessarily supported.

As a back-end developer, I guess there must be a series of software on your desktop, which can be used as a development debugging tool, such as Navicat database connection tool, postman interface debugging tool, pycharm code writing IDE, and other tools. Today, I’d like to introduce some functions you may not know about pycharms, so that your IDE, postman and Navicat can be integrated, and you don’t need to cut the screen frequently.

2、database

I think this function can completely replace Navicat, so where is the database function.

One of the two vertical icons in the upper right corner of pycharm, where you can add a connection to the database.

As you can see, there are many kinds of databases supported, and basically all the mainstream databases can be connected. Here, take MySQL as an example.

Basically the same as Navicat, input the connection name of the database you want to connect, host, port, user, password, database name, and then click test connection to test the connection. The first test may need to download the database connection driver, download it, and the test result can successfully connect to the database you need to connect.

Here I create a new database as a demonstration. You can see that after the connection is successful, all the tables, table fields, field types and field comments in the database can be displayed. After the table is opened, the data display is also very clear. You can also directly add, delete, and modify the table data as Navicat does, which is very convenient for us to test the data when we develop Debugging.

With this tool, Navicat can be abandoned and database visualization can be carried out directly in IDE development tools such as pycharms, so as to avoid the trouble of cutting screens and screens.

3、HTTP Client

There are fewer people who may know about this tool. Usually, when debugging the restful API in our back-end development, the most commonly used tool is postman. This tool is really convenient, but in pycharm, interface debugging can also be completed, that is, HTTP client.

So where is the HTTP client.

After opening

We believe that these functions should be familiar to you all. They are the same as postman. You can send a request and get response information by filling in some necessary requests of an HTTP request. But this method is not suitable for repeated testing and saving. What I recommend next is the information in the blue prompt in the figure above, that is, convert request to the new format. What is the format.

We create a new test directory in the project, and then when we create a new file, there is an HTTP request at the bottom. The default suffix is http. We create a new file for interface testing.

This file is used to define the requested information in a fixed format, such as

First write the request method and URL, then write the request header information, then write the request body (if any), or click add request to quickly generate the request template. Click the small arrow on the left side of the request method to run, and view the results. Here we write two restful APIs to test. What we connect is the database in the previous section, test addition and query.

You can see that the JSON data requested by get is displayed. The display effect is as clear as that of postman.

Try posting a new piece of data into the database. Click the small arrow for post.

You can also request to go to the database to see the results

Xiao Zhao has been added.

For this function, I think it can completely replace postman. We can create a new HTTP request file under test for each of our data models, define get, post, put and delete request information. When we want to test the interface, we can click directly to run it, and then match the database function to directly modify the data of the database. From then on, we can develop three or four software without using Cut back and forth.