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.
django-admin startproject mysite
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')]
python manage.py runserver 127.0.0.1:8000
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