Django~NewProject and APP
2016-02-25 14:07
344 查看
New Project
1.新建 django-admin startproject mysite
2.运行 manage.py runserver 8080
New APP
1.manage.py startapp polls
2.write view.py: def index 等等
3.create urls.py: urlpatterns=[ url() ]
4.url链接到project中:修改添加mysite/urls.py,
5.安装数据库 manage.py migrate
6.creating models
7.Activating models 在mysite/settings.py 中添加一行
8创建编译 manage.py makemigrationgs polls
修改编译manage.py migrate
9运作,输入数据
manage.py shell
import django
django.setup()
-------------
from polls.models import Question,Choice
Question.objects.all()
from django.utils import timezone
q = Question(question_text="What's new?", pub_date=timezone.now())
More Vies
1.vies.py 新增 def detail results vote
2.polls/urls.py新增url
添加模板Template
1.在APP的文件下新建template/app/index.html
2.编辑html文件
3.更新polls/views.py
New 2 APPS
1.manage.py startapp polls2,在project中添加注册
2.copy polls 的templates,新建文件夹修改app name
3.copy修改models,
4.修改urls.
5.修改views
主要所有polls修改为polls2
urls.py中的app_name
views.py中的好多
还有xxx.html中的
Make the poll app modifiable in the admin¶ polls2/admim.py 中添加model
ListView and DetailView
We’re using two generic views here:
通用视图
除了object_list外,Django还提供了许多通用视图函数,分布在几个模块中:
django.views.generic.list_detail模块
object_list 显示模型对象列表 object_detail 显示单个模型对象
django.views.generic.create_update模块
create_object 创建模型对象
update_object 修改模型对象
delete_object 删除模型对象
django.views.generic.simple模块
direct_to_template 直接使用指定的模板渲染给定的context对象
redirect_to 重定向到指定的url
django.views.generic.date_based模块
这个模块主要处理“按时间查看存档”的功能,来源于新闻出版行业。具体包括:
archive_index 最顶级的归档,列出所有年份及指定数量的最新对象
archive_year 按年归档,列出所有拥有对象的月份
archive_month 按月归档,列出本月的所有对象,找到拥有对象的上一个、下一个月份
archive_week 按周归档,列出本周的所有对象
archive_day 按日归档,列出当天的所有对象,找到拥有对象的上一个、下一个日期
archive_today 当前日期(今天)的按日归档
object_detail 显示按照年/月/日/序号找到的对象
1.新建 django-admin startproject mysite
2.运行 manage.py runserver 8080
New APP
1.manage.py startapp polls
2.write view.py: def index 等等
3.create urls.py: urlpatterns=[ url() ]
4.url链接到project中:修改添加mysite/urls.py,
url(r'^polls/', include('polls.urls')),
5.安装数据库 manage.py migrate
6.creating models
7.Activating models 在mysite/settings.py 中添加一行
8创建编译 manage.py makemigrationgs polls
修改编译manage.py migrate
9运作,输入数据
manage.py shell
import django
django.setup()
-------------
from polls.models import Question,Choice
Question.objects.all()
from django.utils import timezone
q = Question(question_text="What's new?", pub_date=timezone.now())
More Vies
1.vies.py 新增 def detail results vote
2.polls/urls.py新增url
添加模板Template
1.在APP的文件下新建template/app/index.html
2.编辑html文件
3.更新polls/views.py
New 2 APPS
1.manage.py startapp polls2,在project中添加注册
2.copy polls 的templates,新建文件夹修改app name
3.copy修改models,
4.修改urls.
5.修改views
主要所有polls修改为polls2
urls.py中的app_name
views.py中的好多
还有xxx.html中的
Make the poll app modifiable in the admin¶ polls2/admim.py 中添加model
from django.contrib import admin from .models import Question admin.site.register(Question)
ListView and DetailView
We’re using two generic views here:
ListViewand
DetailView. Respectively, those two views abstract the concepts of “display a list of objects” and “display a detail page for a particular type of object.”
通用视图
除了object_list外,Django还提供了许多通用视图函数,分布在几个模块中:
django.views.generic.list_detail模块
object_list 显示模型对象列表 object_detail 显示单个模型对象
django.views.generic.create_update模块
create_object 创建模型对象
update_object 修改模型对象
delete_object 删除模型对象
django.views.generic.simple模块
direct_to_template 直接使用指定的模板渲染给定的context对象
redirect_to 重定向到指定的url
django.views.generic.date_based模块
这个模块主要处理“按时间查看存档”的功能,来源于新闻出版行业。具体包括:
archive_index 最顶级的归档,列出所有年份及指定数量的最新对象
archive_year 按年归档,列出所有拥有对象的月份
archive_month 按月归档,列出本月的所有对象,找到拥有对象的上一个、下一个月份
archive_week 按周归档,列出本周的所有对象
archive_day 按日归档,列出当天的所有对象,找到拥有对象的上一个、下一个日期
archive_today 当前日期(今天)的按日归档
object_detail 显示按照年/月/日/序号找到的对象
相关文章推荐
- [Android小技巧]如何不用图片创建一个带圆角的按钮
- Android service ( 一 ) 三种开启服务方法
- Android官方下拉刷新与下拉刷新和上拉加载SwipeRefreshLayout
- Android studio 修改项目字体
- Android Fragment应用实战,使用碎片向ActivityGroup说再见
- Android app开发知识小结
- Webview的使用
- Android MediaRecorder 录音
- Unity MeshFilter导出OBJ文件
- Unity 偏振3D左右格式画面制作
- Unity 实现倒计时 协程
- Unity调用Android保存图片到相册
- Android沉浸式效果实现
- 关于iOS加载webView通过webView跳转回app
- Android 内存 - 获取单个应用内存限制
- Android仿QQ和iOS的ListView左滑出现删除和置顶等操作,可自定义菜单
- iOS开发那些事--性能优化–内存泄露问题的解决
- 探究android:largeHeap
- Nagios 监控系统架设全攻略
- iOS 25个性能优化/内存优化常用方法