Before you start Django profile operations and form form action

The newly created app must register go to settings.py

INSTALLED_APPS = [
                'django.contrib.admin',
                'django.contrib.auth',
                'django.contrib.contenttypes',
                'django.contrib.sessions',
                'django.contrib.messages',
                'django.contrib.staticfiles',
                # 'app01'  # 简写
                'app01.apps.App01Config'  # 全称
            ]

html files all on the default templates folder
for the front section has been written document we just use it to take over these files can be called called "Static file"
static file can be

  Pictures (img)

    css

  js

  Similar to a front-end frame bootstrap class written

Static files all on static default folder under
  static default folder by default subfolders created folder
    css folder of the current site all the style file
    js file js file of the current site all
    img files in the current site all the picture files
    to other (front-end framework code third-party plug-in code ...)

We need to manually add a static file path

 

 

 

= STATIC_URL ' / static / '  
'' ' 
is not a file path, but still want to access the file browser, this must be prefixed with 
' ''

We write in the module folder html files that require following this wording import static files

    <link rel="stylesheet" href="/xxx/bootstrap-3.3.7-dist/css/bootstrap.min.css">
    <script src="/xxx/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>

In order to prevent future changes to a static file prefix

We will unify import static html file written    

{% Load static%} # static dynamic resolution file prefix
     < Link the rel = "this stylesheet" the href = "{% static 'on Bootstrap-3.3.7-dist / CSS / bootstrap.min.css'}%" > 
    < Script the src = "{% static 'on Bootstrap-3.3.7-dist / JS / bootstrap.min.js'}%" > </ Script >

 

Ddjango project started when we must make sure that a port number is only a django project in occupied
otherwise would be likely to cause bug

 

 

 

Users can access all resources in the url
only open the url related resources you can access to (******)

 

 

 

form

The default is to get a request form form

get request data added later get request url path

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

 

Can be replaced by post request method
requires settings to a file comment out after the intermediate post request into

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',
        ]

form form data submitted by the action destination
  default to 1. The current address is not written filed
  2 can also be written suffix / index / (used this project)
  3. The full path can also be written

 

Front-end data acquisition

request.method acquisition request method of 
        
        processing of the data is not just only wsgiref django backend module also done a lot of data processing 
        GET 
            request.GET data acquisition front-end get submitted (it is like a big dictionary) 
            values 
                request.GET.get ( ' username ' )   # Although the default value is a list, but just take a list of the last element 
                # strongly recommended that you use the form values in brackets 
                
                # if you want directly to list all out (******) 
                request.GET .getlist ( ' Hobby ' ) 
        POST 
            request.POST data acquisition front-end post submission (it is like a big dictionary) 
            values 
                request.POST.get ( ' username ' )   #Although the default value is a list, but just take a list of the last element 
                # strongly recommended that you use the form values in brackets 
                
                # if you want directly to list all out (******) 
                request.POST.getlist ( ' Hobby ' )

 

pycharm link database

first step:

 

 

Step two: the first link to the database will need to download drivers

 

 note:

mysql version of the problem because there will be two driver files, not the first to try a second

 

 third step:

Enter your user name, password, and database name you want to connect

 

 the fourth step:

The following point under test button, then successfully apply and ok

 

 

Django database link

django default using built-in sqlite database   
        if you want it to another database needs to be configured in the configuration file settings
         1 .settings file configuration 
                DATABASES = {
             ' default ' : {
                 ' ENGINE ' : ' django.db.backends. MySQL ' ,
                 ' NAME ' : ' day51 ' ,
                 ' the HOST ' : ' 127.0.0.1 ' ,
                 ' PORT ' : 3306 ,
                 'USER' : ' Root ' ,
                 ' PASSWORD ' : ' 123 ' ,
                 ' CHARSET ' : ' utf8 ' 
            } 
}
         2 . Also tell init file in the project name or the name of the application init file django Do not use the default mysqldb mysql connection 
        but rather pymysql 
            Import pymysql 
            pymysql.install_as_MySQLdb ()

 

Guess you like

Origin www.cnblogs.com/asdaa/p/11529041.html