Virtual
1. 安装
pip install virtualenv
2. 创建虚拟环境
virtualenv env # 在当前目录下创建一个env目录的虚拟环境
3. virtualenv 参数
D:\Demos\Pys>virtualenv -h
usage: virtualenv [--version] [--with-traceback] [-v | -q] [--read-only-app-data] [--app-data APP_DATA] [--reset-app-data] [--upgrade-embed-wheels] [--discovery {builtin}] [-p py] [--try-first-with py_exe]
[--creator {builtin,cpython3-win,venv}] [--seeder {app-data,pip}] [--no-seed] [--activators comma_sep_list] [--clear] [--no-vcs-ignore] [--system-site-packages] [--copies] [--no-download | --download]
[--extra-search-dir d [d ...]] [--pip version] [--setuptools version] [--wheel version] [--no-pip] [--no-setuptools] [--no-wheel] [--no-periodic-update] [--symlink-app-data] [--prompt prompt] [-h]
dest
options:
--version display the version of the virtualenv package and its location, then exit
--with-traceback on failure also display the stacktrace internals of virtualenv (default: False)
--read-only-app-data use app data folder in read-only mode (write operations will fail with error) (default: False)
--app-data APP_DATA a data folder used as cache by the virtualenv (default: C:\Users\zzhou\AppData\Local\pypa\virtualenv)
--reset-app-data start with empty app data folder (default: False)
--upgrade-embed-wheels trigger a manual update of the embedded wheels (default: False)
-h, --help show this help message and exit
verbosity:
verbosity = verbose - quiet, default INFO, mapping => CRITICAL=0, ERROR=1, WARNING=2, INFO=3, DEBUG=4, NOTSET=5
-v, --verbose increase verbosity (default: 2)
-q, --quiet decrease verbosity (default: 0)
discovery:
discover and provide a target interpreter
--discovery {builtin} interpreter discovery method (default: builtin)
-p py, --python py interpreter based on what to create environment (path/identifier) - by default use the interpreter where the tool is installed - first found wins (default: [])
--try-first-with py_exe try first these interpreters before starting the discovery (default: [])
creator:
options for creator builtin
--creator {builtin,cpython3-win,venv}
create environment via (builtin = cpython3-win) (default: builtin)
dest directory to create virtualenv at
--clear remove the destination directory if exist before starting (will overwrite files otherwise) (default: False)
--no-vcs-ignore don't create VCS ignore directive in the destination directory (default: False)
--system-site-packages give the virtual environment access to the system site-packages dir (default: False)
--copies, --always-copy try to use copies rather than symlinks, even when symlinks are the default for the platform (default: True)
seeder:
options for seeder app-data
--seeder {app-data,pip} seed packages install method (default: app-data)
--no-seed, --without-pip do not install seed packages (default: False)
--no-download, --never-download
pass to disable download of the latest pip/setuptools/wheel from PyPI (default: True)
--download pass to enable download of the latest pip/setuptools/wheel from PyPI (default: False)
--extra-search-dir d [d ...] a path containing wheels to extend the internal wheel list (can be set 1+ times) (default: [])
--pip version version of pip to install as seed: embed, bundle, none or exact version (default: bundle)
--setuptools version version of setuptools to install as seed: embed, bundle, none or exact version (default: bundle)
--wheel version version of wheel to install as seed: embed, bundle, none or exact version (default: bundle)
--no-pip do not install pip (default: False)
--no-setuptools do not install setuptools (default: False)
--no-wheel do not install wheel (default: False)
--no-periodic-update disable the periodic (once every 14 days) update of the embedded wheels (default: False)
--symlink-app-data not supported - symlink the python packages from the app-data folder (requires seed pip>=19.3) (default: False)
activators:
options for activation scripts
--activators comma_sep_list activators to generate - default is all supported (default: bash,batch,fish,nushell,powershell,python)
--prompt prompt provides an alternative prompt prefix for this environment (value of . means name of the current working directory) (default: None)
config file C:\Users\zzhou\AppData\Local\pypa\virtualenv\virtualenv.ini missing (change via env var VIRTUALENV_CONFIG_FILE)
4. 运行虚拟环境
D:\Demos\Pys>.\env\Scripts\activate.bat
(env) D:\Demos\Pys>
5. 退出虚拟环境
(env) D:\Demos\Pys>deactivate
D:\Demos\Pys>
6. 安装指定版本的django
image.png安装django之后会安装一个django-admin的程序,用来创建和管理django项目
要创建一个Django项目可以运行如下命令
django-admin startproject <project_name>[project_path]
django-admin startproject study_django .
目录 | |
---|---|
study_django/ |
# 项目根目录,目录名可以随意更换 |
study_django/manage.py |
# 管理django项目的命令行工具 |
study_django/study_django/ |
# 项目目录, Python包 |
study_django/study_django/__init__.py |
|
study_django/study_django/settings.py |
# 项目配置文件 |
study_django/study_django/urls.py |
# 项目根路由文件 |
study_django/study_django/asgi.py |
# 兼容asgi协议的web服务器入口文件 |
study_django/study_django/msgi.py |
# 兼容msgi协议的web服务器入口文件 |
7. 运行项目
python .\manage.py runserver 127.0.0.1:8888
image.png
8. 修改时区和语言
# settings.py
# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/
LANGUAGE_CODE = 'zh-hans'
TIME_ZONE = 'Asia/Shanghai'
image.png
网友评论