bae3.0第四步 第一个polls系统
2014-01-24 16:29
381 查看
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/
进入新建的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/
相关文章推荐
- 错误:[将截断字符串或二进制数据。\r\n语句已终止。]
- json全套
- synthesis-of-weak-property-only-allowed-in-arc-or-gc-mode ARC属性
- ubuntu 常见错误--Could not get lock /var/lib/dpkg/lock
- js截取字符串
- Windows 应用程序交互过程
- 联想集团收购IBM x86服务器业务
- cacti监控一览无余
- hdu 2152 有上下界的母函数使用
- Android增量升级的方法和原理详细介绍
- 常用的sql语句
- Gartner对未来几年移动应用的前瞻
- Microsoft Office Professional Plus 2007在安装过程中出错
- 有爱就有恨
- 前尘往事成云烟
- 未设置 WEB 服务器网卡的 DNS,导致外网无法访问
- 图的深度优先遍历,基于邻接链表的非递归实现
- OVER(PARTITION BY)函数介绍
- 管理者如何提升自我?
- IDC:开发人员就业增长率放缓