The first snow in 2018, later than in 2002
I remember sharing a series of articles related to Django development (search on the top right of the blog), including templates, views, routing, and more. Then this article adds some function code blocks commonly used in Django development process, including front-end and back-end related function codes. These code blocks are commonly used in normal development, so make a backup here for easy query.
This feature is often used in the side menu bar, panel folding can effectively keep the interface clean.
The front-end of the table pagination is relatively simple. To achieve true pagination display data, you need to combine the back-end code, which will be introduced later in the article.
Sometimes the content of the cells in the table is too long, which will make the whole table look bad. Therefore, you need to add the following style to the table columns with long content.
Sometimes you need to modify some form data. The previous method is to click a button to jump to a modified page, but this is not elegant enough, so you can choose to pop up an editable dialog box by clicking the button.
This function is mainly used to remove data and remind you when modifying data.
This is awesome. When searching for some resources, is it convenient to autocomplete?
Sending a request with ajax is good or bad. For specific usage, please refer to: https://thief.one/2017/09/14/3/
This is purely for the sake of force.
The table display data is a common function. In general, multiple tabular data is required for deletion, so batch selection is very important. Batch selection in the general table can be achieved using a radio button.
The front page of the front page is introduced, so how does the back end write paging function? The django framework has a built-in paging module Paginator, and other frameworks, such as flask.
However, after using it, the performance is not good, because every time you request a page, you need to get all the data first, and then use this module to calculate the data that this page needs to display. When all the data volume is relatively large, the return is slower (also Maybe I didn’t use this module). So I wrote a paging module myself.
This does not need to query all the data in memory beforehand, but only need to query how many pieces of data exist in total (note that the query here is changed from select
* to select count(
*)). After getting the page returned by the paging function, you can combine the limit function in the sql statement to query the data content to be displayed on the paging page.
This function is used to verify the identity of the user. It can be used with the login function to write a decorator function to check whether there is a session value in the global. (The session value is a dictionary format that is generated when the user logs in.)
If you use it, add it directly on the function that requires permission control:
`For the time being, I thought about it. Let’s remember so much. After that, I will add some more, o.