Django (a: basic concepts and installation configuration)

A: django Description:

django is a heavyweight framework used by many web frameworks in python, the simple describe django: comprehensive. Many successful website and app are based on django development and widespread use. While Django is an open source framework.

django will constantly upgrade from birth, we have many different versions, corresponding to different versions of python. Also has a certain distinction between the different versions of django, it should be used to select the version of the corresponding django python and according to the specific service requirements. It has now developed to django2.2 version, corresponding to the 3.7 version of python. Currently recommend using the latest version, version 2.2 supports python3.5,3.6,3.7.

Two: MVC and MVT:

Mvc:

    Full Name Model View Controller, is a model (model) - view (view) - abbreviation controller (controller) is. A software design model, with a service logic, data, organization code interface display method of separating the business logic to gather a member which, while improving and customization interfaces and user interaction does not need to rewrite the business logic .

These three layers are closely linked, but are independent of each other, changes within each layer without affecting other layers. Each layer provide external interfaces (Interface), one call for it. As a result, the software can be modular, modify the appearance or change data without modifying the other layers, which greatly facilitates maintenance and upgrades.

mvt:

    diango MVT is a framework, in fact, still follow mvc mode, the so-called mvt mvc actually is the same nature and just view HTML is no longer relevant, but the main business logic, the equivalent of the controller. Templates are placed in html, called templates.

    M (model): data layer, is responsible for interacting with the database, data processing.

    V (view): the view layer, the same as with the MVC C, responsible for sending a request, received data, and return data.

    T (template): template, templates responsible for rendering content to the browser.

Three: installation configuration django, and create a project:

Before installing python django make sure that the environment properly, and install a pip.

1: Installation pip Django by:

    pip install django (= 2.1.1) (to specify the version) inside, do not specify the default install the latest version.

2: django detect whether the installation was successful:

    import django

3: Create a django project:

    django-admin.py startproject project name

4: Create an app:

    python manage.py startapp app name (app once created, the name recommended not to change)

5: Startup Items:

    python manage.py runserver

    2. + django version after the successful launch will see a small rocket. . .

Four: django project structure Description:

--manage.py: boot file, and project file commands interactively

--project name:

the mysite
            ├── manage.py
            └── the mysite
                ├── __init__.py
                ├── the settings.py
                ├── the urls.py
                └── wsgi.py
            ---settings.py: configuration information
            --- urls: Path mapping and view function
            --- wsgi: package socket

--app:

the mysite
            Learn /
            ├── __init__.py
            ├── admin.py
            ├── the models.py
            ├── tests.py
            └── the views.py
            --- Models: storage associated with the table structure of APP. Database-related operations.
            --- views: the view function associated with the storage of APP. A processing request issued by the user, coming from a corresponding urls.py, the content may be displayed by the page rendering templates.
            --- admin: background, you can use a small amount of diamante quickly build a strong background.

 

Guess you like

Origin blog.csdn.net/qq_41558265/article/details/90810628