查看现存的虚拟环境:
conda env list
1.创建虚拟环境:
conda create -n venv python=3.6
进入虚拟环境:
activate venv
安装Django:
pip install Django==2.2
进入D盘:
cd d:
2.创建项目:
django-admin startproject mysite1
进入项目:
cd mysite1
3.创建应用:
python manage.py startapp demo
4.编辑视图文件
修改mysite/demo/views.py,增加hello方法
from django.http import HttpResponse
def hello(request):
return HttpResponse("hello world")
5.配置路由
创建mysite/demo/urls.py
from django.urls import path
from .views import hello
urlpatterns = [
path('hello/', hello),
]
修改mysite/mysite/urls.py
from django.contrib import admin
from django.urls import path,include
urlpatterns = [
path('admin/', admin.site.urls),
path('demo/', include('demo.urls')),
]
6.启动服务器
python manage.py runserver
7.访问网站
http://127.0.0.1:8003/demo/hello/
退出python虚拟环境:
conda deactivate