A, django installation configuration

1, install django

Install django

pip install -U django

Check whether the installed django

django-admin

 

2. Create a django project

  • Use the command line to create

Create a project: create a django project in the current path

django-admin startproject dj_test

Create a subdirectory: Create a directory called user in the project below

python manage.py startapp user

  • Creating use pycharm

Select diango when creating the project, fill in the name and application name at its own subprojects in more settings inside, you can click Create.

 

3, start django

Command line to start the project : into the project directory, run this command to start the project

  python manage.py runserver

  pycharm start the project : automatic identification of pycharm django project started clicking on it

 

4, django project directory

 

 

 

5, django configuration

 Here are some common configuration need to be amended

C: \ Users \ Administrator \ Desktop \ dj_lianxi \ dj_lianxi \ settings.py to modify this file settings.py

 

1. Add a subdirectory

INSTALLED_APPS = [

'django.contrib.admin',

'django.contrib.auth',

'django.contrib.contenttypes',

'django.contrib.sessions',

'django.contrib.messages',

'django.contrib.staticfiles',

'User' # added to create their own subdirectories

#INSTALLED_APPS, this is what sub-module inside the tube, user module is of our own creation, if need, will be added to the inside

 

Configuring path of html

TEMPLATES = [

{

'BACKEND': 'django.template.backends.django.DjangoTemplates',

'DIRS': [os.path.join (BASE_DIR, 'templates')], # template directory

'APP_DIRS': True,

'OPTIONS': {

'context_processors': [

'django.template.context_processors.debug',

'django.template.context_processors.request',

'django.contrib.auth.context_processors.auth',

'django.contrib.messages.context_processors.messages',

],

},

},

]

#TEMPLATES local configuration template, you want to modify is DIRS this, change into their own templates directory

 

3. Configuration Database

DATABASES = {

'default': {

'ENGINE': 'django.db.backends.mysql', # mysql database engine change

'NAME': 'db_name', # database name

'USER': 'db_user', # user

'PASSWORD': 'db_password', # password

'HOST': '127.0.0.1',#ip

'PORT': '3306', # port number

}

}

#DATABASES is the configuration database, where sqlite database is used by default, if you want to change mysql, then modified to the above written

# Note that using words mysql database, you need to pay attention to the following 2:00

# 1, use mysql database, then you need to install the module pymysql

# 2, adding __init__.py file inside project folder with that name

#   import pymysql

#   pymysql.install_as_MySQLdb()

 

4. Configuration Language timezone

LANGUAGE_CODE = 'zh-Hans'

#LANGUAGE_CODE language, the default is in English, here into Chinese

 

TIME_ZONE = 'Asia/Shanghai'

 

#TIME_ZONE is the time zone, the default is the standard time zone, where China finished changing the time zone

 

The directory to store css, js, images of

STATICFILES_DIRS = (

os.path.join(BASE_DIR, 'static'),

) # Static files directory

 

#STATICFILES_DIRS directory static files, put some css, js, static folder need to create

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/yanyan-/p/11725809.html