自动化安装
#更新依赖库
pip install --upgrade setuptools
#安装指定的版本
pip install Django==2.0.4
文件式安装
进入到Django文件安装目录,输入命令:
python setup.py install
安装后打印版本号
python -m django –version
切记在数据库里面新建一个 数据库名(myitems)
生成Django项目 (myitems为自己定义的项目名)
django-admin startproject myitems
注意,有的django-admin找不到问题,需要配置环境变量
启动服务
python manage.py runserver
本地化中间件(这个在settings.py里面修改的)
'django.mididdleware.locale.LocaleMiddleware',
先win+R
C:Users太阳之泪>cd www
C:Users太阳之泪www>cd myitems
C:Users太阳之泪wwwmyitems>python manage.py makemigrations
No changes detected
C:Users太阳之泪wwwmyitems>python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying auth.0008_alter_user_username_max_length... OK
Applying auth.0009_alter_user_last_name_max_length... OK
在初始化__init__.py里面输入
import pymysql
在settings.py配置数据库
在settings.py里面配置文件