摘要: Django的通用视图抽象出了一些在视图开发中常用的代码和模式,这样就可以在无需编写大量代码的情况下,快速编写出常用的数据视图。Django内建通用视图实现如下功能:完成常用的简单任务:重定向到另外一个界面以及渲染一个指定的模板显示列表和某个特定对象的详细内容界面。呈现基于日期的数据的年/月/日归档界面,关联的详细页面,最新页面。使用通用视图from django.conf.urls.defaults import *from django.views.generic.base import TemplateViewurlpatterns = patterns('', (r&# 阅读全文
posted @ 2012-09-05 20:21 事件轮询,回不到过去 阅读(345) 评论(0) 推荐(0) 编辑
摘要: South的简单说明:在django中如果我们已经syncdb之后,再增加或者删除属性列的时候,djnago自带的sybcdb并不能够再次同步,这个工具不能同步models和数据库,是有缺陷的,可以用south作为代替其的工具,South 能够检测对models的更改并同步到数据库。South的基本使用方法:安装South:fedora下 #sudo easy-install South;将South作为app添加到setting文件中:INSTALL_APP添加south;对于第一次使用的情况:python manage.py schemamigration yourappname --in 阅读全文
posted @ 2012-09-03 13:58 事件轮询,回不到过去 阅读(671) 评论(0) 推荐(0) 编辑
摘要: 714558923Accessing Foreign Key ValuesWhen you access a field that’s a ForeignKey, you’ll get the related model object. For example:>>> b = Book.objects.get(id=50)>>> b.publisher<Publisher: Apress Publishing>>>> b.publisher.websiteu'http://www.apress.com/'With 阅读全文
posted @ 2012-09-02 17:01 事件轮询,回不到过去 阅读(515) 评论(0) 推荐(0) 编辑
摘要: Automatic HTML Escaping-----------> user-submitted data shouldn't be trusted blindly and inserted directly into your Webpage, because a malicious user could use thin kind of hole to do potentially bad things, This type of security exploit is called a Cross site scipting(XSS) attack. Consider 阅读全文
posted @ 2012-08-31 16:31 事件轮询,回不到过去 阅读(574) 评论(0) 推荐(0) 编辑
摘要: Context 是一个传递给模版的名称到值的映射,类似python字典。 模版渲染就是通过从context获取值来替换模版中变量并执行所有的模版标签。 RequestContext默认的在模版context中加入了一些变量,如HttpRequest对象或当前登陆用户的相关信息。当你不想在一系列模版中都明确指定一些相同的变量时,应该使用RequestContext。例如考虑下面两个图: from django.template import loader, Contextdef view_1(request): .......... t = loader.ge... 阅读全文
posted @ 2012-08-30 20:52 事件轮询,回不到过去 阅读(299) 评论(0) 推荐(1) 编辑
摘要: 什么是TCP/IP============> TCP/IP是因特网的通信协议,通信协议是计算机必须遵守的规则的描述,只有遵守这些规则,计算机才能相互通信,浏览器和服务器都在使用TCP/IP,电子邮件也在使用,因特网地址也是TCP/IP。 Transmission Control Protocol / Internet Proctocol 传输控制协议,网际协议。 定义了电子设备如何连入因特网,以及数据如何在它们之间传输的标准。在TCP/IP内部============> 包含了一系列用于处理数据通信的协议:TCP-应用程序之间的通信 传输控制协议UDP-用户数据报协议,应用程序.. 阅读全文
posted @ 2012-08-30 16:31 事件轮询,回不到过去 阅读(430) 评论(0) 推荐(0) 编辑
摘要: 伪造捕捉到的URLconf的值:要匹配某个模式的一堆视图,以及一个并不匹配这个模式但视图逻辑是一样的URL。这种情况下,可以通过向同一个视图传递额外URLconf参数来伪造URL值的捕捉。例如,一个显示特定日子的应用。类似:/mydata/jan/01//mydata/jan/02//mydata/jan/03/# .../mydata/dec/30//mydata/dec/31/使用命名组方法在URLconf中捕捉:urlpatterns = patterns('', (r'^mydata/(?P<month>\w{3})/(?P<day>\d 阅读全文
posted @ 2012-08-30 15:24 事件轮询,回不到过去 阅读(915) 评论(0) 推荐(0) 编辑
摘要: URLconf的技巧---------第一种 每一个入口包括了它所关联的视图函数 直接传递一个函数对象 <-----------------------from django.conf.urls.defaults import *from mysite.views import hello, current_datetime, hours_ahead <===============urlpatterns = patterns('', (r'^hello/$', hello), (r'^time/$', current_datetim 阅读全文
posted @ 2012-08-30 11:12 事件轮询,回不到过去 阅读(325) 评论(0) 推荐(0) 编辑
摘要: 显示错误如下:TypeError at /books/contact/'instancemethod' object has no attribute '__getitem__'Request Method: POSTRequest URL: http://127.0.0.1:8000/books/contact/Django Version: 1.4.1Exception Type: TypeErrorException Value: 'instancemethod' object has no attribute '__getitem 阅读全文
posted @ 2012-08-29 15:43 事件轮询,回不到过去 阅读(4710) 评论(0) 推荐(0) 编辑
摘要: Forbidden (403)CSRF verification failed. Request aborted.HelpReason given for failure: CSRF token missing or incorrect. In general, this can occur when there is a genuine Cross Site Request Forgery, or when Django's CSRF mechanism has not been used correctly. For POST forms, you need to ensure.. 阅读全文
posted @ 2012-08-29 14:28 事件轮询,回不到过去 阅读(4665) 评论(0) 推荐(0) 编辑