Django Girl系列一 Django的安装
(1)安装虚拟环境以及安装Django
以D盘为例:
D: #进入D盘
mkdir djangogirls #新建一个文件夹
cd djangogirls #进入这个文件夹
python3 -m venv myvenv #下载虚拟环境,虚拟环境的名字为:myvenv
myvenv\Scripts\activate #使用虚拟环境
pip install django #安装Django
结果:
(2)创建一个Django项目
django-admin startproject mysite .
目录结构为:
djangogirls
├───manage.py
└───mysite
settings.py
urls.py
wsgi.py
__init__.py
(3)更改设置
settings.py中的第108行改为:
TIME_ZONE = 'Asia/Shanghai'
setting.py中第120行改为:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
在命令行中创建一个数据库:
python manage.py migrate
输出结果为:
(myvenv) ~/djangogirls$ 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 admin.0003_logentry_add_action_flag_choices... 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
Applying sessions.0001_initial... OK
(4)开启服务器
python manage.py runserver