1、创建自己的app
进入新建的blog工程目录,执行其下面的manage.py来创建polls应用,命令为:
python manage.py startapp polls
2、定义app的models
Each model is represented by a class that subclasses django.db.models.Model.
Each model has a number of class variables, each of which represents a database field in the model.
for example:
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
3、安装app
Edit the settings.py file, and change the INSTALLED_APPS setting to include the string 'polls'.
4、创建app需要的表
4.1、生成app需要的表创建sql执行命令: python manage.py sql polls
4.2、在数据库中执行上面生成的sql语句。
5、add __unicode__() methods to your models
We use __unicode__() here because Django models deal with Unicode by default.
All data stored in your database is converted to Unicode when it's returned.
Django models have a default __str__() method that calls __unicode__()
and converts the result to a UTF-8 bytestring.
This means that unicode(p) will return a Unicode string,
and str(p) will return a normal string, with characters encoded as UTF-8.
6、Make the poll app modifiable in the admin
Open polls/admin.py,and edit it to look like this:
from polls.models import Poll
admin.site.register(Poll)
如果想自己定义管理界面,那么自定义一个类,并重新注册,如:
class PollAdmin(admin.ModelAdmin):
fields = ['pub_date', 'question']
admin.site.register(Poll, PollAdmin)
7、Customizing your project’s templates
by default, Django automatically looks for a templates/ subdirectory within each application package
8、修改工程的urls.py
添加内容: url(r'^polls/', include('polls.urls', namespace="polls")),
9、中间用到的文件可以参考django的官方网站https://docs.djangoproject.com/en/1.6/intro/tutorial03/

bae3.0第四步 第一个polls系统的更多相关文章

  1. petshop4.0 具体解释之中的一个(系统架构设计)

    前言:PetShop是一个范例,微软用它来展示.Net企业系统开发的能力.业界有很多.Net与J2EE之争,很多数据是从微软的PetShop和Sun的PetStore而来.这样的争论不可避免带有浓厚的 ...

  2. bae3.0第三步 添加默认管理后台模块和mysql库

    1.创建数据库 先在本地的mysql数据库中创建数据库db_blog,执行python manage.py syncdb来创建表. 然后将数据库中的表导入到bae上的数据库中.2.配置数据库 修改项目 ...

  3. ElasticSearch第四步-查询详解

    ElasticSearch系列学习 ElasticSearch第一步-环境配置 ElasticSearch第二步-CRUD之Sense ElasticSearch第三步-中文分词 ElasticSea ...

  4. [原创]css3简单几步画一个乾坤图

    效果如上,鼠标移上去会有动画. 代码如下非常简单: <html> <head> <style> .outer{height:100px;width:200px;bo ...

  5. Ajax发送异步请求(四步操作)

    1.第一步(得到XMLHttpRequest) *ajax其实只需要学习一个对象:XMLHttpRequest,如果掌握了它,就掌握了ajax!! *得到XMLHttpRequest >大多数浏 ...

  6. Linux强化论:15步打造一个安全的Linux服务器

    Linux强化论:15步打造一个安全的Linux服务器 Alpha_h4ck2016-11-30共28761人围观 ,发现 8 个不明物体专题系统安全 可能大多数人都觉得Linux是安全的吧?但我要告 ...

  7. BAE3.0上的java+tomcat代码发布

    ---------------------------------2016/01/25更新-------------------------------------- 最近两天去百度开放云,发现它再也 ...

  8. 文件下载(只需要简单的四步),Java中都通用

    我们就直接切入主题啦,文件下载只需要四步: 1.设置文件ContentType类型 2.设置文件头 3.通过response获取ServletOutputStream对象(out) 4.写到输出流(o ...

  9. 四步完成ajax的使用

    什么是ajax? ajax(异步javascript xml) 能够刷新局部网页数据而不是重新加载整个网页. 如何使用ajax? 第一步,创建xmlhttprequest对象,var xmlhttp ...

随机推荐

  1. 20165101刘天野 2017-2018-2 《Java程序设计》第5周学习总结

    #20165101刘天野 2017-2018-2 <Java程序设计>第5周学习总结 教材学习内容总结 第七章:内部类与异常类 内部类(nested classes),面向对象程序设计中, ...

  2. unbunto关闭触摸屏

    sudo rmmod psmouse 这个是禁用的 sudo modprobe psmouse 这个是启用的

  3. MongoDB快速入门(一)

    MongoDB是一个跨平台,面向文档的数据库,提供高性能,高可用性和易于扩展.MongoDB是工作在集合和文档上一种概念. 数据数 数据库是一个集合的物理容器.每个数据库获取其自己设定在文件系统上的文 ...

  4. centos 源码安装php5.5

    系统环境: CentOS 6.5 / 7.0 x86_64 Fedora 20 x86_64下载 PHP 源码包 # wget http://cn2.php.net/distributions/php ...

  5. Windows 7安装PHP运行环境和开发环境

    1. 安装Apache 下载地址:http://www.apache.org/dyn/closer.cgi/httpd/binaries/win32 如需更改端口:打开Apache安装目录下conf目 ...

  6. 【bzoj1876】[SDOI2009]SuperGCD(高精度)

    题目传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=1876 一道简单的高精度+Stein算法(或者叫辗转相除法)求最大公约数板子题. md还 ...

  7. netty上手

    关于netty的基础NIO,请参见:NIO原理及实例 下面介绍Netty的上手使用: 首先为项目添加jar依赖: <dependency> <groupId>io.netty& ...

  8. whois老域名挖掘技术

    我一般通过站长工具域名WHOIS查询定向收集一些特定域名,拿来分析网站存活站点. 例如: 查询域名基本信息 WHOIS反查得到大部分域名注册信息 一般大一点的厂商都有几百个域名,我们通过此处收集大量顶 ...

  9. Linux嵌入式 -- 内核 - 内核链表

    1. linux内核链表 链表数据结构的定义: struct list_head  {  struct list_head *next, *prev;  };  list_head结构包含两个指向li ...

  10. Spring data jpa 使用技巧记录

    软件152 尹以操 最近在用Springboot 以及Spring data jpa  ,使用jpa可以让我更方便的操作数据库,特开此帖记录使用jpa的一些小技巧. 一.使用spring data j ...