一、安装Django
pip install Djangopython
二、版本号查询
python -m django --versiondjango
三、建立项目
切换到你想建立项目的目录,执行命令:django-admin startproject dayang浏览器
命令执行成功后生成项目,目录结构以下:服务器
外面的一层目录dayng 是项目的容器,注意不能命名为Djangoapp
manage.py: 一个实用的命令行工具,可以让你以各类方式与该 Django 项目进行交互。ide
The inner dayang/ directory is the actual Python package for your project. Its name is the Python package name you’ll need to use to import anything inside it (e.g. dayang.urls).工具
dayang/__init__.py: 一个空文件,告诉 Python 该目录是一个 Python 包。this
dayang/settings.py: Django 项目的配置文件.url
dayang/urls.py: The URL declarations for this Django project; a “table of contents” of your Django-powered site.spa
dayang/wsgi.py: 一个 WSGI 兼容的 Web 服务器的入口,以便运行你的项目。
四、运行django项目
切换到目录dayang执行命令:manage.py runserver
浏览器输入http://127.0.0.1:8000/看到如下界面
运行成功!
小贴士:修改端口命令【manage.py runserver 8080】
五、建立app
切换到manage.py同级目录,执行命令:manage.py startapp polls
如今的结构目录以下:
六、编写你的第一个视图
To call the view, we need to map it to a URL - and for this we need a URLconf.
新建文件urls.py
The next step is to point the root URLconf at the polls.urls module.
运行命令:manager.py runserver
查看运行结果: