The Django framework MVC is actually very simpleLet's look at a simple example where you can tell how the functionality of the web framework is different from the way it was before. Here's an example of how to do this by using Django: First, we split into 4 python files (models.py, views.py, urls.py) and HTML template
Create a new Django project:Such asAdd Project directory File: test_db, (if the file does not exist, a new folder will be created in that directory)Set app Name: TestDB, open the project in a new window,wherein, in the MVC pattern, models.py is used to process m,views.py for processing v,urls.py for mapping views.1. Download Pymysql:pip Install Pymysql2. Add (not) in Project __init__.py:Import PymysqlPymysql.install_as_mysqldb ():Fields that define da
Describes QuerySets and djangoquerysets In the Python Django framework.
Django's QuerySets are cool!
In this article, I will explain what QuerySets are and how they work (if you are familiar with it, you can jump directly to the second part ), I think you should always return the QuerySets object if you can. Let's talk about how to do it.QuerySets is cool
QuerySet is essentially a list of objects of a given
Look at a picture First!1. Request Life cycle
-Wsgi, which is the socket server, is used to receive user requests and to first encapsulate the request, and then hand over the request to the Web framework (Flask, Django)
-Middleware that helps us validate requests or add other related data to the request object, for example: CSRF, request.session
-Route Matching
-View functions, which ha
This article describes how to use the inclusion_tag in the Python Django framework. the example in this article is based on Python's earlier 2. x version. if you need it, you can refer to another common template tag to display data by rendering other templates. For example, in the background management interface of Django, it uses a custom template tag to display
This article describes how to use the object list view in the Django framework. Django is one of the most famous popular Python web frameworks, if you need a friend, you can refer to direct_to_template. it is undoubtedly very useful, but the most useful part of Django's general view is to present data in the database. Because this application is so common,
, sale)VALUES(6,'To learn to spit with six dolls .', the, $,1);SQL data name: main_app01_productIn all of the above examples, the filters we construct simply compare the field values to a constant. What if we were to compare the values of two fields?Django provides F () to make such comparisons. An instance of F () can reference a field in a query to compare the values of two different fields in the same model instance.Example 1:Query for items with a
)) print (BOOKINFO19)--Aggregate function# need to import module from django.db.models Import * table name. objects.aggregate (Sum (field name)) 1.avg2.count# The total number of queries is generally not used; BookInfo.objects.count () substitution; 3. Max4.Min5.Sumbookinfo20 = BookInfo.objects.aggregate (Sum (' Book_read ')) print (BOOKINFO20)--Correlation query--one-to-many, one class1. Get the Single Field object Object1 = table name. Objects.get (' condition ') #
Let's look at a simple example where you can tell how the functionality of the web framework is different from the way it was before. Here's an example of how to do this by using Django: First, we split into 4 python files (models.py, views.py, urls.py) and HTML template files (latest_books.html).
models.py:
1
# models.py (the database tables)
2
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.