目录
第二部分 项目-Web应用
第十八章 Django 入门
Django-helloworld
第一块搞什么虚拟环境?
大致了解了下是为了不同版本冲突或者维护独立可运行环境的一个控制手段。
https://blog.csdn.net/godot06/article/details/81079064
hello-world版本,先无脑按照书上来一遍看看效果,增加下性趣。
ruishens-MacBook-Pro:python_work ruishen$ mkdir learning_log
ruishens-MacBook-Pro:python_work ruishen$ cd learning_log/
ruishens-MacBook-Pro:learning_log ruishen$ ll
total 0
drwxr-xr-x 2 ruishen staff 64 6 18 15:37 .
drwxr-xr-x 44 ruishen staff 1408 6 18 15:37 ..
ruishens-MacBook-Pro:learning_log ruishen$ python3 -m venv ll_env
ruishens-MacBook-Pro:learning_log ruishen$ source ll_env/bin/activate
(ll_env) ruishens-MacBook-Pro:learning_log ruishen$ ❶
(ll_env) ruishens-MacBook-Pro:learning_log ruishen$ ll
total 0
drwxr-xr-x 3 ruishen staff 96 6 18 15:42 .
drwxr-xr-x 44 ruishen staff 1408 6 18 15:37 ..
drwxr-xr-x 6 ruishen staff 192 6 18 15:42 ll_env
(ll_env) ruishens-MacBook-Pro:learning_log ruishen$ source ll_env/bin/activate
(ll_env) ruishens-MacBook-Pro:learning_log ruishen$ pip3 install Django
Collecting Django
Downloading Django-3.2.4-py3-none-any.whl (7.9 MB)
|████████████████████████████████| 7.9 MB 25.0 MB/s
Collecting pytz
Downloading pytz-2021.1-py2.py3-none-any.whl (510 kB)
|████████████████████████████████| 510 kB 34.4 MB/s
Collecting sqlparse>=0.2.2
Downloading sqlparse-0.4.1-py3-none-any.whl (42 kB)
|████████████████████████████████| 42 kB 1.8 MB/s
Collecting asgiref<4,>=3.3.2
Downloading asgiref-3.3.4-py3-none-any.whl (22 kB)
Installing collected packages: sqlparse, pytz, asgiref, Django
Successfully installed Django-3.2.4 asgiref-3.3.4 pytz-2021.1 sqlparse-0.4.1
WARNING: You are using pip version 21.1.1; however, version 21.1.2 is available.
You should consider upgrading via the '/Users/ruishen/python_work/learning_log/ll_env/bin/python3 -m pip install --upgrade pip' command.
(ll_env) ruishens-MacBook-Pro:learning_log ruishen$ python3 -m pip install --upgrade pip
Requirement already satisfied: pip in ./ll_env/lib/python3.9/site-packages (21.1.1)
Collecting pip
Using cached pip-21.1.2-py3-none-any.whl (1.5 MB)
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 21.1.1
Uninstalling pip-21.1.1:
Successfully uninstalled pip-21.1.1
Successfully installed pip-21.1.2
(ll_env) ruishens-MacBook-Pro:learning_log ruishen$ django-admin.py startproject learning_log .
/Users/ruishen/python_work/learning_log/ll_env/bin/django-admin.py:17: RemovedInDjango40Warning: django-admin.py is deprecated in favor of django-admin.
warnings.warn(
(ll_env) ruishens-MacBook-Pro:learning_log ruishen$ ❷ll
-bash: ❷ll: command not found
(ll_env) ruishens-MacBook-Pro:learning_log ruishen$ ls
learning_log ll_env manage.py
(ll_env) ruishens-MacBook-Pro:learning_log ruishen$ ll
total 8
drwxr-xr-x 5 ruishen staff 160 6 18 15:43 .
drwxr-xr-x 44 ruishen staff 1408 6 18 15:37 ..
drwxr-xr-x 7 ruishen staff 224 6 18 15:43 learning_log
drwxr-xr-x 6 ruishen staff 192 6 18 15:42 ll_env
-rwxr-xr-x 1 ruishen staff 668 6 18 15:43 manage.py
(ll_env) ruishens-MacBook-Pro:learning_log ruishen$ ls learning_log/
__init__.py asgi.py settings.py urls.py wsgi.py
(ll_env) ruishens-MacBook-Pro:learning_log ruishen$ python3 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 auth.0010_alter_group_name_max_length... OK
Applying auth.0011_update_proxy_permissions... OK
Applying auth.0012_alter_user_first_name_max_length... OK
Applying sessions.0001_initial... OK
(ll_env) ruishens-MacBook-Pro:learning_log ruishen$ ls
db.sqlite3 learning_log ll_env manage.py
(ll_env) ruishen