Django installation, creation, configuration and configuration

django installation

pip install django==2.1.4

django3 database connection can only be used with mysqlclient, django2 pymysql it can also be used instead of mysqlclient, if you want to use pymysql write code in __init__.py in settings.py file with the same level of the directory: 

import pymysql 
    pymysql.install_as_MySQLdb()

The project according to the actual use of the database link is not pymysql what to choose django version, otherwise it will report the following error

mysqlclient 1.3.13 or newer is required; you have 0.9.3

 Of course, the solution is still there, not here go into details. You can find on the stackoverflow.

 

Create a django project
1, you can use the command line to create
django-admin startproject mysite
2, can also be used pycharm user interface to create an image
 

Configuration settings.py  

# Here to add a profile, html, css configuration file path to the database, etc.

1. Database related

EGNIGE: Engine mysql sqllite3
NAME: Name of the database
HOST: IP 
PORT: Port number 3306
USER: User Name
PASSWORD password '' 

2. Static related files

STATIC_URL = 'static' # Aliases
STATICFILES_DIRS = [
os.path.join(BASE_DIR,'static'),
]

3. APP

INSTALLED_APPS = [
'App01.apps.App01Config', # tell Django myself a new application is named app01
# 'app01'
]

4. CSRF 
  commented CSRF middleware may submit a form POST request form
5. The TEMPLATES
  'the DIRS': [the os.path.join (base_dir, 'Templates')]

 

Run Django project
1, the command line to run the project
python manage.py runserver 127.0.0.1:8000
2, can also be used to run Django pycharm, but it needs to be configured. Tip Pycharm to pressing on the line.

 

File Structure Classification
mysite/
├── manage.py # file management
└── mysite # project directory
    ├── __init__.py
    ├── settings.py # here to add the configuration file, html, css configuration file path to the database, etc.
    ├── urls.py # routing -> URL correspondence relations and functions, where the function to add background processing
    └── wsgi.py # runserver command module on the use of wsgiref do a simple web server

 

 urls.py # routing -> URL correspondence relations and functions, where the function to add background processing.

# # Add corresponding functions in it 
DEF Login (Request):
     "" "
    : Param request: a request with all relevant data is encapsulated inside objects to request this
    :return:
    """
    # return HttpResponse("ok")
    return render(request, 'login.html')


urlpatterns = [
    URL (R & lt ' ^ Login / ' , Login), # # where the parameter is added to the front of the regex 
] # # Here add the path

 

 

 


 

 
 
 
 
 

Guess you like

Origin www.cnblogs.com/hercules-chung/p/12459760.html