Django~NewProject and APP
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中的
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: 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还提供了许多通用视图函数,分布在几个模块中:
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 显示按照年/月/日/序号找到的对象
Django~NewProject and APP的更多相关文章
- django 添加comments app
django 添加comments app 参看 django comments 文档 安装和配置comments 1.安装comments,运行:pip install django-contrib ...
- django根据不同app配置相应的log文件
django根据不同app配置相应的log文件 settings.py # django logging LOG_PATH = "/var/log/blog/" LOGGING = ...
- Django中的APP
3. Django中的APP: 什么是APP?以及为什么要用APP? project --> 项目 (老男孩教育大学校) APP --> 应用 (Linux学院/Python学院/大数据学 ...
- Django 加载 app 中的urls
在 blog app 下创建 urls.py, 定义该 app 下自有的 url : new/story from blog import views from django.conf import ...
- Django --- Django下载和APP创建 ORM (大概步骤)
1,下载: 命令行: pip install django == 1.11.15 pip install -i或 源 django == 1.11.15 pycharm settings 解释器 点 ...
- Django:同一个app支持多个数据库
我以我个人的Mynote工程说明,目的是要在backend这个app里面设置不同的model对应daysn和bear两个数据库进行操作 现在我们先简单对一个完全新建的django工程配置一个自动在my ...
- Django学习手册 - 创建Django工程项目以及APP
前置步骤: 下载python,django 并且安装好 python 解释器以及django模块. 整体步骤阐述: 创建django工程项目 步骤一:进入安装的python目录 步骤二:输入创建工程的 ...
- django 数据库配置 ,APP 迁移.模型基础
# 1.数据库的连接配置django 连接mysql的配置流程:- 安装 pymysql pip install pymysql- 创建数据库用户有创建数据库权限的用户- 创建数据库crm .进入数据 ...
- [django实践]投票app
code: https://github.com/lannyMa/toupiao polls app介绍 这个例子来源于django官网,恰好2.x版本有中文版. https://docs.djang ...
随机推荐
- 【转】使用Eclipse构建Maven项目 (step-by-step)
安装eclipse 及配置maven时,参考的资料!!! from:http://blog.csdn.net/qjyong/article/details/9098213 Maven这个个项目管理和构 ...
- mysql搜索引擎 小结
mysql搜索引擎 小结 mysql5.5以后,mysql默认使用InnoDB存储引擎. 若要修改默认引擎,可以修改配置文件中的default-storage-engine.可以通过show vari ...
- POJ 2029 Get Many Persimmon Trees
Get Many Persimmon Trees Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3243 Accepted: 2 ...
- Codeforces Round #270 1001
Codeforces Round #270 1001 A. Design Tutorial: Learn from Math time limit per test 1 second memory l ...
- jquery获取文本框的内容
使用jquery获取文本框的内容有以下几种: 1.根据ID取值(id属性): // javascript <script type="text/javascript"> ...
- Ubuntu 14 安装 Chrome/Chromium flash播放器
在命令终端中执行如下命令即可: sudo apt-get install pepperflashplugin-nonfree sudo update-pepperflashplugin-nonfree ...
- CK-Editor content.replace
<s:property value="content.replace('\n\r', '<br/>')" escape="false"/> ...
- 联不上网 Unable to initialize Windows Sockets interface. General failure.
电脑莫名联不上网 Unable to initialize Windows Sockets interface. General failure. Unable to initialize the W ...
- Java多线程基础知识(六)
一. Java中的线程池 线程池的作用: 1. 降低资源消耗 2. 提高响应速度 3. 提高线程的可管理性 线程池处理流程: 1. 线程池判断核心线程池线程是否都在执行任务,如果不是,则创建一个新的工 ...
- Linux文件读写机制及优化方式
导读 Linux是一个可控性强的,安全高效的操作系统.本文只讨论Linux下文件的读写机制,不涉及不同读取方式如read,fread,cin等的对比,这些读取方式本质上都是调用系统api read,只 ...