Windows下Django项目创建

1. 创建Django项目文件夹

D:\Sweetyaya> mkdir DjangoDemo3
D:\Sweetyaya> cd DjangoDemo3

2. 创建虚拟环境

D:\Sweetyaya\DjangoDemo3> virtualenv venv
created virtual environment CPython3.7.6.final.0-64 in 960ms
  creator CPython3Windows(dest=D:\Sweetyaya\DjangoDemo3\venv, clear=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=C:\Users\***\AppData\Local\pypa\virtualenv)
    added seed packages: pip==21.0.1, setuptools==53.0.0, wheel==0.36.2
  activators BashActivator,BatchActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator

4. 进入虚拟环境

D:\Sweetyaya\DjangoDemo3> venv\Scripts\activate

(venv) D:\Sweetyaya\DjangoDemo3>

退出的命令是 deactivate

5. 安装Django包

(venv) D:\Sweetyaya\DjangoDemo3> pip install django
Collecting django
  Using cached Django-3.1.7-py3-none-any.whl (7.8 MB)
Collecting pytz
  Using cached pytz-2021.1-py2.py3-none-any.whl (510 kB)
Collecting asgiref<4,>=3.2.10
  Using cached asgiref-3.3.1-py3-none-any.whl (19 kB)
Collecting sqlparse>=0.2.2
  Using cached sqlparse-0.4.1-py3-none-any.whl (42 kB)
Installing collected packages: sqlparse, pytz, asgiref, django
Successfully installed asgiref-3.3.1 django-3.1.7 pytz-2021.1 sqlparse-0.4.1

6. 创建Django项目

(venv) D:\Sweetyaya\DjangoDemo3> django-admin startproject DjangoDemo3 .

7. 创建应用

(venv) D:\Sweetyaya\DjangoDemo3> django-admin startapp MyFirstApp

8. 启动服务

(venv) D:\Sweetyaya\DjangoDemo3> python manage.py runserver 8765
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.
March 06, 2021 - 17:23:47
Django version 3.1.7, using settings 'DjangoDemo3.settings'
Starting development server at http://127.0.0.1:8765/
Quit the server with CTRL-BREAK.

9. 测试

浏览器访问地址 http://127.0.0.1:8765/ ,可将 Django 的图标,同时命令行可见如下

[06/Mar/2021 17:23:56] "GET / HTTP/1.1" 200 16351
[06/Mar/2021 17:23:56] "GET /static/admin/css/fonts.css HTTP/1.1" 200 423
[06/Mar/2021 17:23:56] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 200 85876
[06/Mar/2021 17:23:56] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 200 86184
[06/Mar/2021 17:23:56] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 200 85692

.OK!

.
.
.
.
.
.


桃花仙人种桃树,又摘桃花换酒钱_

相关推荐
©️2020 CSDN 皮肤主题: 创作都市 设计师:CSDN官方博客 返回首页