Python Django学习笔记
2016-07-09 11:30
531 查看
创建django vritualenv
至此,django已经安装完毕。开始创建,第一个django project吧。
下面,开始了解下项目目录中每个文件吧。
manage.py:包含了管理django服务相应的控制命令,其中的内不需要更改。
firstProject/wsgi.py:启动一个兼容wsgi的服务的接口
firstProject/settings.py:django项目的配置脚本,暂时无序修改
firstProject/urls.py:https://docs.djangoproject.com/en/1.9/topics/http/urls/
启动server:
新建一个app:
在firstProject/urls.py中增加:
修改firstProject/firstApp/views.py
重新启动server。输入http://127.0.0.1:8000/firstApp/。页面即可返回“hello firstrapp“
virtualenv firstDjangoApp source firstDjangoApp pip install django (firstDjangoApp) fangfenghuadeMacBook-Pro:django fangfenghua$ django-admin help check usage: django-admin check [-h] [--version] [-v {0,1,2,3}] [--settings SETTINGS] [--pythonpath PYTHONPATH] [--traceback] [--no-color] [--tag TAGS] [--list-tags] [--deploy] [app_label [app_label ...]] Checks the entire Django project for potential problems. positional arguments: app_label optional arguments: -h, --help show this help message and exit --version show program's version number and exit -v {0,1,2,3}, --verbosity {0,1,2,3} Verbosity level; 0=minimal output, 1=normal output, 2=verbose output, 3=very verbose output --settings SETTINGS The Python path to a settings module, e.g. "myproject.settings.main". If this isn't provided, the DJANGO_SETTINGS_MODULE environment variable will be used. --pythonpath PYTHONPATH A directory to add to the Python path, e.g. "/home/djangoprojects/myproject". --traceback Raise on CommandError exceptions --no-color Don't colorize the command output. --tag TAGS, -t TAGS Run only checks labeled with given tag. --list-tags List available tags. --deploy Check deployment settings.
至此,django已经安装完毕。开始创建,第一个django project吧。
django-admin startproject firstProject (firstDjangoApp) fangfenghuadeMacBook-Pro:django fangfenghua$ tree firstProject firstProject ├── firstProject │ ├── __init__.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py └── manage.py
下面,开始了解下项目目录中每个文件吧。
manage.py:包含了管理django服务相应的控制命令,其中的内不需要更改。
firstProject/wsgi.py:启动一个兼容wsgi的服务的接口
firstProject/settings.py:django项目的配置脚本,暂时无序修改
firstProject/urls.py:https://docs.djangoproject.com/en/1.9/topics/http/urls/
启动server:
python manage.py runserver $ip:$port
新建一个app:
firstrApp/ ├── __init__.py ├── admin.py ├── apps.py ├── migrations │ └── __init__.py ├── models.py ├── tests.py └── views.py
在firstProject/urls.py中增加:
url(r'^firstrApp/', views.firstApp)
修改firstProject/firstApp/views.py
(firstDjangoApp) fangfenghuadeMacBook-Pro:firstProject fangfenghua$ cat firstProject/firstApp/views.py from django.shortcuts import render from django.http import HttpResponse # Create your views here. def firstApp(request): return HttpResponse("hello firstrapp")
重新启动server。输入http://127.0.0.1:8000/firstApp/。页面即可返回“hello firstrapp“
相关文章推荐
- 浅谈Python装饰器
- Python中的yield from语法
- 【已解决】UnicodeEncodeError: ‘gbk’ codec can’t encode character u’\u200e’ in position 43: illegal multib
- Python的"数组"储存
- python中如何区分常量和变量
- python学习——数据类型和变量
- python之路 socket、socket server
- Python time模块学习
- python学习——Python基础
- python学习——输入和输出
- python学习——使用文本编辑器
- 程序员的基础生存技能:高效用Google--2016-07-08 Python开发者
- python学习——从hello word开始
- [python]Django集成Paypal支付小结
- python安装
- python3.0_day9_scoket基础之篇
- mysql-python安装时EnvironmentError: mysql_config not found
- 5.4 Python类
- wxPython安装与GUI
- python中if __name__ == '__main__': 的解析