WEB hand line and frame

Hand line and web frameworks

Software development framework

C / S architecture: client / server

B / S architecture: browser / server

Bs is the essence of cs

HTTP protocol

http is a hypertext transfer protocol

1. Four characteristics

  • Over TCP / IP based application layer acting
  • Based on a request response
  • Stateless (cookie session token ..)
  • No connection (long connection websocket (http protocol large patch))

2. Data Format

  • Request format
    • The first line of the request (request method, protocol version.)
    • Request header (a lot of k: v key-value pairs) Note that the space between the head and the request for the request body \ r \ n
    • Request body (real data, and when we send post requests, if it is get request)
  • Response format
    • The first line of response
    • Note that the response in response to the head space between the head and the body in response to
    • Response Body

3. Response Status Code

    • Represent some meaning in particular digital
    • 1 xx: the server has successfully received your data is being processed, you can continue to submit additional data
    • 2 xx: server success response (200 requests the successful)
    • 3 xx: Redirection (eg user is not logged let him jump to the login page).
    • 4 xx: Error Request (requested resource does not exist 404, 403 access denied)
    • 5 xx: internal server error (such as 500 server is down)

Request method

get request:

  • To others towards data

post request:

  • Submit data to others (for example: the logged on user)

url :

  • The same resource locator

Hand line and web frameworks

Based wsgiref module

  • urls.py: Routing and object-relational view function
  • views.py: put the view function (that is, some business logic processing)
  • templates: Templates folder (that is, a bunch of html file)

HTTP protocol

1. Pure hand line and web frameworks

  • Manually writing socket
  • Manual data processing format http

2. Based on wsgiref module

  • The above process module implements two manual
  • Depending on the split function has become different py file
  • ursl.py: a correspondence relationship which is a function of the view route
  • views.py: put view function (function class)
  • When you split is complete, if you want to add functionality, you only need to add two places above it

3. Dynamic and static pages

  • Static pages
    • Data is written dead, is unchanged
  • dynamic webpages
    • Data is acquired in real time
    • E.g:
      • Get the back end to the front to show the current time
      • Data acquisition database back-end to the front end of the display

Three mainstream python web framework

Django

  1. There are many large and comes with features similar to the full level account
  2. But sometimes the past will seem heavy, after all, something too right

Flask

  1. Small but excellent, comes with features like excellent special little trumpet
  2. But particularly his third-party modules, if it's third-party modules can then add up to more than Django
  3. And it is more dependent on the module with the three parties, but a collapse of the module, it will cool, the equivalent of a big brother to help bring it in

Tornado

  1. Asynchronous non-blocking feature that can be regressed to develop the game server. (Support high concurrent ah)

A difference between these three

A: socket part

B: corresponding relationship between routing and view function

C: template syntax

Django:

  • A use of someone else (such as: wsgiref)
  • Write your own B
  • Write your own C

Flask:

  • A use of someone else's werkzeug (based wsgiref)
  • Write your own B
  • C with others jinja2

Tornado:

  • Niubi three are to write their own

Precautions

  1. The Chinese name of the computer is not in
  2. A window is a project pycharm
  3. Project also try not to use the name in Chinese

Django version of the problem

  1. X 2. X market now with more or 1. X's (recommended 1.11.9 - 1.11.13)

Djando installation

  • pip3 install django==1.11.11

Verify your installation was successful

  • Command line direct knock Django-admin

A brief introduction to the app in Django project

  1. A django project is equivalent to a university, while the app is similar to the inside of the University.
  2. django is actually used to write one application
  3. A app is equivalent to a separate function (such as your user function, your management)
  4. django support any multiple app

How to use Django

Use the command line

  • Create a django project: (django-admin startproject mysite)
  • Start django project: (python manage.py runserver)
  • Create an application app :( python manage.py startapp app01)

Precautions

  1. The newly created app you need to register settings in the configuration file and pycharm will help you register the first application you write in the creation of the project
  2. Using the command line to create a Django project, will not help you create templates folder, you can create yourself
  3. In the settings file, you need to manually write the configuration (os.path.join (BASE, 'remplates')) in the TEMPLATES
  4. Django's when you start, you must make sure that only one port project a djiango

django project in correspondence

title

The same name and project folder

settings.py exposed to the user's profile

urls.py view function Routing and a correspondence relationship

Application name

migrations in folders database migration records

admin.py django Admin

apps.py registration related

models.py model class

tests.py test file

views.py store view function

templates html files in folders

manage.py django file entrance

Guess you like

Origin www.cnblogs.com/kangwy/p/11718011.html