- 全新Win10下安装开发环境记录
- 安装VScode
- 安装Git
- 安装Python3.71
- VScode安装好相关插件
- 新建好文件夹用 VScode 打开
- code-终端-新建终端
- 要创建虚拟环境,请使用以下命令,其中“env”是环境文件夹的名称:
1 py -3 -m venv env
- 进入虚拟环境文件夹
cd env
- 安装指定版本DJango
pip3 install django==1.11.11
- 安装依赖
pip3 install pylint pylint_django
- 输出已安装了 Django 和运行着的版本号
python -c "import django; print(django.get_version())"
- 新建项目mysite
django-admin.py startproject mysite
- 出错:VSCode直接弹出django-admin.py,因为设置了VSCode为.py文件的打开方式,改为Python,exe
- 进入mysite项目文件夹(项目 mysite下还有个 mysite文件夹)
cd mysite
- 创建名为polls的APP
python manage.py startapp polls
- 出错,错误代码:
1 Traceback (most recent call last): 2 File "manage.py", line 22, in <module> 3 execute_from_command_line(sys.argv) 4 File "C:\Users\William\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\__init__.py", line 364, in execute_from_command_line 5 utility.execute() 6 File "C:\Users\William\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\__init__.py", line 338, in execute 7 django.setup() 8 File "C:\Users\William\AppData\Local\Programs\Python\Python37\lib\site-packages\django\__init__.py", line 27, in setup 9 apps.populate(settings.INSTALLED_APPS) 10 File "C:\Users\William\AppData\Local\Programs\Python\Python37\lib\site-packages\django\apps\registry.py", line 85, in populate 11 app_config = AppConfig.create(entry) 12 File "C:\Users\William\AppData\Local\Programs\Python\Python37\lib\site-packages\django\apps\config.py", line 94, in create 13 module = import_module(entry) 14 File "C:\Users\William\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module 15 return _bootstrap._gcd_import(name[level:], package, level) 16 File "<frozen importlib._bootstrap>", line 1006, in _gcd_import 17 File "<frozen importlib._bootstrap>", line 983, in _find_and_load 18 File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked 19 File "<frozen importlib._bootstrap>", line 677, in _load_unlocked 20 File "<frozen importlib._bootstrap_external>", line 728, in exec_module 21 File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed 22 File "C:\Users\William\AppData\Local\Programs\Python\Python37\lib\site-packages\django\contrib\admin\__init__.py", line 4, in <module> 23 from django.contrib.admin.filters import ( 24 File "C:\Users\William\AppData\Local\Programs\Python\Python37\lib\site-packages\django\contrib\admin\filters.py", line 10, in <module> 25 from django.contrib.admin.options import IncorrectLookupParameters 26 File "C:\Users\William\AppData\Local\Programs\Python\Python37\lib\site-packages\django\contrib\admin\options.py", line 12, in <module> 27 from django.contrib.admin import helpers, widgets 28 File "C:\Users\William\AppData\Local\Programs\Python\Python37\lib\site-packages\django\contrib\admin\widgets.py", line 152 29 ‘%s=%s‘ % (k, v) for k, v in params.items(), 30 ^ 31 SyntaxError: Generator expression must be parenthesized
- 打开28行代码的文件
C:\Users\William\AppData\Local\Programs\Python\Python37\lib\site-packages\django\contrib\admin\widgets.py
- 找到152行,删掉,号保存文件,重新运行 ‘创建名为polls的APP’ 的代码
- 以指定端口8001运行Django
python manage.py runserver 8001
- 打开http://127.0.0.1:8001/看见如下内容即为搭建成功
It worked!
Congratulations on your first Django-powered page.
Next, start your first app by running python manage.py startapp [app_label]
.
You‘re seeing this message because you have DEBUG = True
in your Django settings file and you haven‘t configured any URLs. Get to work!
VScode 搭建 django 开发环境(Win Python3.71 django1.11.11)
原文地址:https://www.cnblogs.com/WilliamB/p/10840556.html
时间: 2024-12-07 18:25:52