标签:
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,
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中的
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: ListView
and 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还提供了许多通用视图函数,分布在几个模块中:
这个模块主要处理“按时间查看存档”的功能,来源于新闻出版行业。具体包括:
标签:
原文地址:http://www.cnblogs.com/lynclynn/p/5216818.html