在Windows中搭建开发环境(django)
- 输入配置venv的命令,其中的env为虚拟环境的放置目录:
E:\django_project> python -m venv env
- 建完成后,输入env\Scripts\activate.bat,即可进入虚拟环境:
E:\django_project> env\Scripts\activate.bat (env) E:\django_project>
- 盘符前有(env)标识说明进入venv成功
- 在虚拟环境中,输入命令 pip install django==2.1
(env) E:\django_project> pip install django==2.1
Collecting django==2.1
Using cached
...
...
Successfully installed django-2.1
(env) E:\django_project>
(env)E:\django_project>django-admin startproject my_blog
- 运行Django服务器,要运行这个django服务器,首先要进入my_blog文件夹,即含有manage.py文件的那个:
(env) E:\django_project>cd my_blog
(env) E:\django_project\my_blog>
- 输入命令python manage.py runserver:
(env) E:\django_project\my_blog>python manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
You have 15 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.
August 20, 2018 - 17:32:34
Django version 2.1, using settings 'my_blog.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
- 在浏览器内输入http://127.0.0.1:8000/就可以看到效果了