1. Terminal Command
# View django version $ Python -m django - Version # Create a project called mysite $ django - ADMIN startproject mysite # start django $ Python manage.py the runserver $ Python manage.py the runserver 8080 $ manage.py the runserver Python 0.0 . 0.0 : 8000 # to create applications, and ensure the same directory as manage.py is $ Python manage.py startapp polls # run the migration to create a model change $ Python manage.py makemigrations # running application model changes to the database $ manage.py the migrate Python # ADMIN created administrator user $ python manage.py createsuperuser
2. Generate directory structure looks like FIG.
3. Configuration file (settings.py)
1, just create a django project, start writing the program, the first step must first register in the configuration file app
INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'app01', # 注册app ]
2, the database connection
= DATABASES { ' default ' : { ' ENGINE ' : ' django.db.backends.mysql ' , ' NAME ' : ' database name ' , ' the USER ' : ' the root ' , ' PASSWORD ' : ' XXX ' , ' the HOST ' : '' , ' PORT ' : '' , } }
Note: The use of the internal Django MySQL connection is MySQLdb module, and also no such python3 module, it is necessary to replace the use of pymysql
1. Install pymsql
$ PIP install pymysql
2. The following configuration is provided in __init__.py project with the same name is placed in
Import pymysql
pymysql.install_as_MySQLdb ()
3. Configure a static file
STATICFILES_DIRS = ( os.path.join(BASE_DIR,'static'), )
Note: You need to create a static folder under the project