Django Learning Diary 1 -- Initialization

工具:VScode

环境:virtualenv,python,django

步骤:

1. 配置Virtualenv:

  • 安装virtualenv: > pip install virtualenv
  • Initial virtualenv:> virtualenv dirname
  • activate virtualenv: > .\env\Scripts\activate
    • 此时可能会出现权限问题,可在管理员模式下的powershell里输入以下代码:
> Get-ExecutionPolicy

> Set-ExecutionPolicy remoteSigned then choose 'A'

  • Create Django project:

> django-admin startproject projectName

> python manage.py startapp app

2. 安装vscode

3. 在vscode里分别安装Material Icon Theme, Son of Obsidian Theme, Python, Django,XML Tools, Beautify, View In Browser, HTML CSS Support, Path Intellisense

4. Vscode interface configuration:

在setting里输入:


{

    "editor.fontSize": 16,

    "explorer.confirmDragAndDrop": false,

    "extensions.autoUpdate": false,

    "workbench.colorTheme": "Son of Obsidian",

    "editor.fontFamily": "Consolas, Dengxian",

    "workbench.sideBar.location": "left",

    "workbench.startupEditor": "newUntitledFile",

    "workbench.iconTheme": "material-icon-theme",

}

5. 配置python环境:选择做导航栏第四个图标(或按Ctrl+Shift+D),在DEBUG右边选择Python。

Django Learning Diary 1 -- Initialization_第1张图片
Initialising python
此时在文件中会弹出.vscode文件夹,里面有2个文件,分别为launch.json 和settings.json(可能不会自动生成,可以自己添加)            
Django Learning Diary 1 -- Initialization_第2张图片
automaticly generated config files
在launch.json里找到Python.Django,并在‘args’加入端口号‘8080’(可为其他)
Django Learning Diary 1 -- Initialization_第3张图片
Add Port number
在settings.json里将interpreter改为virtualenv里面的python(注意是双斜杠)
Change python path to virtualenv

6. install 语法检测和代码格式化工具:


> pip install pylint

> pip install pylint_django

> pip install yapf

小结:

  1. 创建虚拟环境来自定义pip安装package
  2. 用Plugins(Material Icon Theme/Son of Obsidian Theme)美化Vscode
  3. 配置Python+Django环境,注意python path和port number;
> django_admin startproject dirName
> python manage.py startapp appName

你可能感兴趣的:(Django Learning Diary 1 -- Initialization)