Home > Article > Backend Development > How to use Django to connect to the database in python (picture and text)
The content of this article is about how to use Django to connect to the database in python (pictures and texts). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
Three elements of form form submission data:
1. The form form tag must have action and method attributes; the value of the action key represents the submission address of the information in the html page. The value of the method key indicates the method used to submit
2. All tags that obtain user input must be placed in the form and must have a name attribute; the value of the name key indicates the information to be submitted
3. There must be a submit button.
request related attributes:
request refers to the request sent by the browser to the server.
1. request.method -- What is returned is the requested method (all uppercase): GET POST...
Note: Watch the method source code to learn:
##
In HTML pages, there are often "method='post'" and the like that stipulate that the method should be lowercase when obtaining the value. In this case, both upper and lower case are acceptable. When the value is obtained from the method, ' upper' will capitalize all the request methods in the method. 2. request.GET - Obtain the parameters in the URL, a data structure similar to a dictionary (if submitted using the get method, use GET to obtain) 3. request.POST -- The data submitted by post is similar to a dictionary data structure (if you submit it using the post method, you must use POST to obtain it) Django's template language {{variable name }}Connect to mysqlUse ORM (Object Relationship Model) to translate SQL statements.Advantages: High development efficiency; No need to write SQL statements directly during developmentDisadvantages: low execution efficiencyCreate app application in Django projectCreate a Python package in the project, different functions are placed in different packages,Create app --Python manage.py startapp app name (example: app01)Indicates in Django that an app has been created:Find INSTALLED_APPS in settings.py and add the new app
4. Create a class (customized class name) in the models.py file under the app application. This class must inherit models.Model, You can use ORM language to write the table structure in the created class 5. Execute the command and sentence to complete the operation of the table in the databasepython manage. py makemigrations -- Record the changes in models.py and update the operations to be performed on the database python manage.py migrate -- Translate the change records into SQL statements and complete the operations in the database.
## ORM query
User.objects.filter(email='', pwd='')
The above is the detailed content of How to use Django to connect to the database in python (picture and text). For more information, please follow other related articles on the PHP Chinese website!