Django

1. What is the Django
web development framework
2. For the installation of Django,
see the official website
pip install Django


3. HTTP basics 1. The message format of
the request (request) sent by the browser to the server : 1. The method path protocol of the request line request\r\n 2. The request body k1:v1\r\n k2:v2 \r\n \r\n 3. Request data 2. The server sends a response to the browser. Response format 1. Response line. HTTP/1.1 status code status descriptor\r\n 2. Response body k1: v1\r\n k2:v2\r\n \r\n 3. Response content













The difference between a static website and a dynamic website is that
static is hard-coded and
dynamic is that everyone is different. The essence is the replacement of strings. 1. The
essence of web is
that the client communicates with the server
. Execute different functions according to different user access paths c Read content from HTML to complete string replacement



4. Classification of web frameworks in python
1. Comes with a, b, c --> tornado
2. Framework comes with b, c, uses third-party a --> Django
3. Framework comes with b, uses third-party a, c-->Flask
is another dimension of division
1. Django is large and complete (you can use it to make a website.
2. Other Flask lightweight provides core functions


5. Create the first Django project
jango-admin, py startproject The project name
gets the following directory structure:
$ cd HelloWorld/
$ tree
.
|-- HelloWorld represents the container of the project
| |-- __init__.py An empty file, telling Python the A directory is a Python package.
| |-- settings.py Settings/configuration for this Django project.
| |-- urls.py URL declarations for this Django project; a "directory" of web sites powered by Django.
| `-- wsgi.py An entry point for a WSGI compatible web server to run your project.
`-- manage.py A useful command-line tool that lets you interact with this Django project in various ways.

Run the first Django project
to enter the created container directory, execute python manage.py runserver 0.0.0.0 means that other computers can connect: 8000 default port number (you can also set it yourself)


6. View and URL configuration
from django.http import HttpResponse

def hello(request):
return HttpResponse("Hello world ! ")


from django.conf.urls import url

from . import view

urlpatterns = [
url(r'^$', view.hello),
url(r'^hello$', view.hello),
]

7. url() function
(1) regex: regular expression, the matching URL will execute the corresponding second parameter view
(2) view: URL request for performing regular expression matching
(3) kwargs: view The parameter of the dictionary type used
(4) name: used to get the URL in reverse

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324935934&siteId=291194637