Django links MySQL, database migration

The default is to get a request form form submitting data

http://127.0.0.1:8000/login/?username=admin&password=123

action

1 do not write, submit data to the current default address

2 full path

3 suffix (/ index)

When submitting post requests, you need to go to the configuration file comment out the line

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    # 'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

The request object

Request to retrieve a front embodiment

request.method # The result is a pure capital string GET / POST

request.POST

Post acquisition request submitted data, similar to a large dictionary <QueryDict: { 'name': [ 'kai'], 'pwd': [ 'kai']}>

request.POST.get () # will only remove the last element in the list

request.POST.getlist () # remove the entire list

request.GET

request.GET.get () # will only remove the last element in the list

request.GET.getlist () # remove the entire list

Django link mysql

We need to create a good library in advance

1 to go to the configuration file configuration-related parameters

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'day50',
        'HOST': '127.0.0.1',
        'PORT': 3306,
        'USER': 'root',
        'PASSWORD': '123123',
        'CHARSET': 'utf8'
    }
}

2 configuration item name or application name following __init__.py

import pymysql
pymysql.install_as_MySQLdb()

Database migration command

python manage.py makemigrations

Just change your records to the database migrations folder inside

python manage.py migrate

It is really synchronized to the database

Guess you like

Origin www.cnblogs.com/kai-/p/12151041.html