Using Flask framework to implement Web page and database data interconnection + common status codes

Source: Internet
Author: User
Tags connection pooling

1. Install two packages from Pip via Cygwin: Pymysql, SQLAlchemy;
2. Import the package in the library we want to use in app.py: Create_engine,text
: from sqlalchemy import create_engine,text
This is followed by a series of operations such as connection pooling: using Engine/connectionpooling/dialect for database operations, the Engine uses connectionpooling to connect to the database:

db_engine = create_engine(      ‘mysql+pymysql://root:密码@127.0.0.1:3306/zhangxindb‘,      connect_args={‘charset‘: ‘utf8‘}, pool_recycle=60, pool_size=5)
 @app. Route ('/login ', methods=[' POST ', ' GET ') def login  (): if Request.method =  ' POST ': Span class= "Hljs-comment" ># print (request.form[' username ']) print (Request.form[ Emailaccounts ']) print (Request.form[ ' password ']) Statement=text (  "select * from Zhuce where Accounts=:eat '". Bindparams (Eat=request.form[ Emailaccounts ']) rows=db_engine.execute (statement). Fetchall () print (rows) return render_template ( ' login.html ')     
    1. I personally find it difficult to understand that statement=text ("' SELECT * from zhuce where Accounts=:eat '). Bindparams (
      eat=request.form[' emailaccounts ') This passage has been pondering for a long time,
      In fact, from the table we built in the database to get the relevant information we enter the corresponding value on the page, instead of We go to execute SQL statements in the database, "Zhuce" is the name of a table I built in "zhangxindb",: Eat can be understood as I in int i, is a definition of the median value, the following "eat=request.form[' Emailaccounts '" is the value of the mailbox account obtained from the Web page to pass to eat this median value, eat and then pass the song value to the database in the corresponding accounts value;
      2. Rows=db_engine.execute (statement). Fetchall ()//Initialize database connection connection string for connection

Plug in a good python operation MySQL article: https://www.cnblogs.com/pangguoping/p/5720322.html

The results of the query are as shown
3. Common HTTP Status codes:
Continue
The initial request has been accepted and the customer should continue to send the remainder of the request
101 Switching protocols
The server translates the client's request to another protocol
OK
Everything is OK, answer documents for Get and post requests follow the back
201 Created
The server has created the document, and the location header gives its URL.
202 Accepted
The request has been accepted, but the processing has not been completed.
203 non-authoritative Information
The document has returned normally, but some of the answer headers may be incorrect because a copy of the document is used
204 No Content
Without a new document, the browser should continue to display the original document. This status code is useful if the user refreshes the page periodically and the servlet can determine that the user's document is new enough.
205 Reset Content
There is no new content, but the browser should reset what it displays. Used to force the browser to clear form input
206 Partial Content
The client sends a GET request with a range header, and the server finishes it
Multiple Choices
The documents requested by the customer can be found in multiple locations that are listed in the returned document. If the server wants to make a preference, it should be indicated in the location answer header.
301 Moved Permanently
The document requested by the customer elsewhere, the new URL is given in the location header, and the browser should automatically access the new URL.
302 Found
Similar to 301, but the new URL should be treated as a temporary replacement instead of permanent.
303 See other
Similar to 301/302, the difference is that if the original request is Post,location header The specified redirect target document should be fetched by get
304 Not Modified
The client has a buffered document and issues a conditional request (typically providing a if-modified-since header indicating that the customer only wants to update the document than the specified date). The server tells the customer that the original buffered document can continue to be used.
305 Use Proxy
The document requested by the customer should be extracted from the proxy server indicated by the location header
307 Temporary Redirect
Same as 302 (Found). Many browsers incorrectly respond to a 302 response for redirection, even if the original request is post, even though it can actually be redirected only if the answer to the POST request is 303. For this reason, HTTP 1.1 has been added in 307 to allow for more cleanup of the region in several status codes: When a 303 response occurs, the browser can follow the redirected get and post requests, and if the 307 answer, the browser can only follow the redirect to the GET request.
Request
A syntax error occurred in the request.
401 Unauthorized
The customer attempted to access a password-protected page without authorization. A www-authenticate header is included in the answer, and the browser displays the user name/Password dialog box, and then makes a request again after filling in the appropriate authorization header.
403 Forbidden
The resource is not available.
404 Not Found
Unable to find resource at the specified location
405 Method not allowed
The request method (GET, POST, HEAD, Delete, PUT, Trace, and so on) does not apply to the specified resource.
406 Not acceptable
The specified resource has been found, but it has a MIME type and is incompatible with the client specified in the Accpet header
407 Proxy Authentication Required
Similar to 401, indicates that the customer must be authorized by the proxy server first.
408 Request Timeout
The customer has not made any requests during the waiting time for the server license. Customers can repeat the same request at a later time.
409 Conflict
Usually related to put requests. The request cannot succeed because the request conflicts with the current state of the resource.
410 Gone
The requested document is no longer available, and the server does not know which address to redirect to. It differs from 404 in that returning 407 means that the document has permanently left the specified location, and 404 indicates that the document is unavailable for unknown reasons.
411 Length Required
The server cannot process the request unless the customer sends a content-length header.
412 Precondition Failed
Some of the prerequisites specified in the request header failed
413 Request Entity Too Large
The size of the destination document exceeds the size that the server is currently willing to handle. If the server thinks it can process the request later, it should provide a retry-after header
414 Request URI Too Long
Uri too long
416 Requested Range not satisfiable
The server does not meet the range header specified by the customer in the request
Internal Server Error
The server encountered an unexpected situation and could not complete the customer's request
501 Not implemented
The server does not support the functionality required to implement the request. For example, a customer issues a put request that is not supported by the server
502 Bad Gateway
When the server acts as a gateway or proxy, the server returns an illegal response in order to complete the request to access the next server
503 Service Unavailable
The server failed to answer due to maintenance or heavy load. For example, a servlet might return 503 if the database connection pool is full. A retry-after header can be supplied when the server returns 503
504 Gateway Timeout
Used by a server acting as a proxy or gateway, indicating that a reply cannot be received from a remote server in a timely manner
505 HTTP Version not supported
The server does not support the HTTP version indicated in the request
Learn this today and continue tomorrow~~~

Using Flask framework to implement Web page and database data interconnection + common status codes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.