相关文档
1、验证python和pip3环境
C:\Users\Administrator>python
Python 3.12.3 (tags/v3.12.3:f6650f9, Apr 9 2024, 14:05:25) [MSC v.1938 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()C:\Users\Administrator>pip3 list
Package Version
------- -------
pip 24.0
2、windows10 虚拟环境设置
C:\Users\Administrator>pip3 install virtualenvwrapper-win
Collecting virtualenvwrapper-winDownloading virtualenvwrapper_win-1.2.7-py3-none-any.whl.metadata (10 kB)
Collecting virtualenv (from virtualenvwrapper-win)Downloading virtualenv-20.26.2-py3-none-any.whl.metadata (4.4 kB)
Collecting distlib<1,>=0.3.7 (from virtualenv->virtualenvwrapper-win)Downloading distlib-0.3.8-py2.py3-none-any.whl.metadata (5.1 kB)
Collecting filelock<4,>=3.12.2 (from virtualenv->virtualenvwrapper-win)Downloading filelock-3.14.0-py3-none-any.whl.metadata (2.8 kB)
Collecting platformdirs<5,>=3.9.1 (from virtualenv->virtualenvwrapper-win)Downloading platformdirs-4.2.1-py3-none-any.whl.metadata (11 kB)
Downloading virtualenvwrapper_win-1.2.7-py3-none-any.whl (18 kB)
Downloading virtualenv-20.26.2-py3-none-any.whl (3.9 MB)━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.9/3.9 MB 42.0 MB/s eta 0:00:00
Downloading distlib-0.3.8-py2.py3-none-any.whl (468 kB)━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 468.9/468.9 kB 28.7 MB/s eta 0:00:00
Downloading filelock-3.14.0-py3-none-any.whl (12 kB)
Downloading platformdirs-4.2.1-py3-none-any.whl (17 kB)
Installing collected packages: distlib, platformdirs, filelock, virtualenv, virtualenvwrapper-win
Successfully installed distlib-0.3.8 filelock-3.14.0 platformdirs-4.2.1 virtualenv-20.26.2 virtualenvwrapper-win-1.2.7
3、安装Django
C:\Users\Administrator>pip3 install django
Collecting djangoDownloading Django-5.0.6-py3-none-any.whl.metadata (4.1 kB)
Collecting asgiref<4,>=3.7.0 (from django)Downloading asgiref-3.8.1-py3-none-any.whl.metadata (9.3 kB)
Collecting sqlparse>=0.3.1 (from django)Downloading sqlparse-0.5.0-py3-none-any.whl.metadata (3.9 kB)
Collecting tzdata (from django)Downloading tzdata-2024.1-py2.py3-none-any.whl.metadata (1.4 kB)
Downloading Django-5.0.6-py3-none-any.whl (8.2 MB)━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 8.2/8.2 MB 43.5 MB/s eta 0:00:00
Downloading asgiref-3.8.1-py3-none-any.whl (23 kB)
Downloading sqlparse-0.5.0-py3-none-any.whl (43 kB)━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 44.0/44.0 kB 2.2 MB/s eta 0:00:00
Downloading tzdata-2024.1-py2.py3-none-any.whl (345 kB)━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 345.4/345.4 kB ? eta 0:00:00
Installing collected packages: tzdata, sqlparse, asgiref, django
Successfully installed asgiref-3.8.1 django-5.0.6 sqlparse-0.5.0 tzdata-2024.1C:\Users\Administrator>py -3 -m django --version
5.0.6
C:\Users\Administrator>python -m django --version
5.0.6
4、测试你的安装
1)创建文件夹及项目目录
D:\django>dirVolume in drive D is 新加卷Volume Serial Number is B68C-03F7Directory of D:\django2024/05/14 21:56 <DIR> .
2024/05/14 21:56 <DIR> django_test0 File(s) 0 bytes2 Dir(s) 240,186,601,472 bytes freeD:\django>cd django_test
2)使用 django-admin 工具创建一个名为“mytestsite”的新框架站点
D:\django\django_test>django-admin startproject mytestsiteD:\django\django_test>dirVolume in drive D is 新加卷Volume Serial Number is B68C-03F7Directory of D:\django\django_test2024/05/14 21:59 <DIR> .
2024/05/14 21:56 <DIR> ..
2024/05/14 21:59 <DIR> mytestsite0 File(s) 0 bytes3 Dir(s) 240,186,593,280 bytes freeD:\django\django_test>cd mytestsiteD:\django\django_test\mytestsite>dirVolume in drive D is 新加卷Volume Serial Number is B68C-03F7Directory of D:\django\django_test\mytestsite2024/05/14 21:59 <DIR> .
2024/05/14 21:59 <DIR> ..
2024/05/14 21:59 688 manage.py
2024/05/14 21:59 <DIR> mytestsite1 File(s) 688 bytes3 Dir(s) 240,186,585,088 bytes free
3)在这个文件夹中使用manager.py和runserver命令运行开发 web 服务器
D:\django\django_test\mytestsite>python3 manage.py runserver
The system cannot execute the specified program.D:\django\django_test\mytestsite>python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...System check identified no issues (0 silenced).You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
Error: You don't have permission to access that port.D:\django\django_test\mytestsite>python manage.py migrate
Operations to perform:Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:Applying contenttypes.0001_initial... OKApplying auth.0001_initial... OKApplying admin.0001_initial... OKApplying admin.0002_logentry_remove_auto_add... OKApplying admin.0003_logentry_add_action_flag_choices... OKApplying contenttypes.0002_remove_content_type_name... OKApplying auth.0002_alter_permission_name_max_length... OKApplying auth.0003_alter_user_email_max_length... OKApplying auth.0004_alter_user_username_opts... OKApplying auth.0005_alter_user_last_login_null... OKApplying auth.0006_require_contenttypes_0002... OKApplying auth.0007_alter_validators_add_error_messages... OKApplying auth.0008_alter_user_username_max_length... OKApplying auth.0009_alter_user_last_name_max_length... OKApplying auth.0010_alter_group_name_max_length... OKApplying auth.0011_update_proxy_permissions... OKApplying auth.0012_alter_user_first_name_max_length... OKApplying sessions.0001_initial... OKD:\django\django_test\mytestsite>python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...System check identified no issues (0 silenced).
Error: You don't have permission to access that port.D:\django\django_test\mytestsite>python manage.py runserver 800
Watching for file changes with StatReloader
Performing system checks...System check identified no issues (0 silenced).
May 14, 2024 - 22:03:22
Django version 5.0.6, using settings 'mytestsite.settings'
Starting development server at http://127.0.0.1:800/
Quit the server with CTRL-BREAK.[14/May/2024 22:03:41] "GET / HTTP/1.1" 200 10629
Not Found: /favicon.ico
[14/May/2024 22:03:41] "GET /favicon.ico HTTP/1.1" 404 2113
4)web浏览器上验证
浏览器上访问http://localhost:800