随笔分类 -  django

1 2 3 4 下一页

the introduction for django
django 实现指定文件合并成压缩文件下载
摘要:需求是在一列学生列表中选择指定的学生,然后下载他们上传的报告文档。用Js构造一个表单将选中的学生学号传递到后台$('#output_student').click(function () { var arr = new Array(); var s... 阅读全文

posted @ 2015-04-08 15:50 颓废的悠然 阅读(2406) 评论(0) 推荐(0)

一天只能触发一次操作
摘要:需求: 学生可以给予导师评价,但是一天只能给予一次评价。 数据库: class Appraise(models.Model): TYPE = ( (1, u'差'), (2, u'中'), (3, u'好'), ) student =... 阅读全文

posted @ 2015-04-07 12:03 颓废的悠然 阅读(383) 评论(0) 推荐(0)

django Q和F查询
摘要:Q查询——对对象的复杂查询F查询——专门取对象中某列值的操作1、对象(django.db.models.Q)可以对关键字参数进行封装,从而更好地应用多个查询,例如:from django.db.models import Qnews=New.objects.filter(Q(question__st... 阅读全文

posted @ 2015-04-06 23:16 颓废的悠然 阅读(805) 评论(0) 推荐(0)

django分页linaro-django-pagination
摘要:1.安装linaro-django-paginationsettingsINSTALLED_APPS = ( # ... 'linaro_django_pagination',) MIDDLEWARE_CLASSES = ( # ... 'linaro_django_pag... 阅读全文

posted @ 2015-04-01 23:37 颓废的悠然 阅读(439) 评论(0) 推荐(0)

django FileFIeld和ImageField 上传路径改写
摘要:def get_file_path(instance, filename): return 'file/document/%s/%s/%s' % (instance.period.code, instance.student.college.code, filename)class Docum... 阅读全文

posted @ 2015-04-01 17:23 颓废的悠然 阅读(2157) 评论(0) 推荐(0)

Django内置template标签
摘要:html过滤{% autoescape on|off %} {{body}} {% endautoescape %}注释{% comment %} {% endcomment %}csrf攻击 {% csrf_token %}循环选择 {% cycle %} 使用当前循环选择 ... .... 阅读全文

posted @ 2015-01-22 21:59 颓废的悠然 阅读(399) 评论(0) 推荐(0)

CBV进阶(一)
摘要:http_method_names , http_method_not_allowd用途:views只接受这些请求.范围ViewDefault:['get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace']get_conte... 阅读全文

posted @ 2015-01-19 16:46 颓废的悠然 阅读(227) 评论(0) 推荐(0)

FormView用法
摘要:功能描述:学生可以对相应学校机构进行投诉建议.form表单class SuggestForm(forms.Form): TYPE_CHOICES = ( (0, u'学校'), (1, u'学院'), (2, u'校院'), ) conte... 阅读全文

posted @ 2015-01-19 13:37 颓废的悠然 阅读(1271) 评论(0) 推荐(0)

深入select_related与prefetch_related函数
摘要:阅读博客http://blog.jobbole.com/74881/的笔记在数据库有外键的时候,使用select_related()和prefetch_related()可以很好的减少数据库请求的次数,从而提高性能.下面是数据库设计图models.py如下:from django.db import... 阅读全文

posted @ 2015-01-18 18:05 颓废的悠然 阅读(4530) 评论(0) 推荐(1)

django中间件templates写法
摘要:def templates_context_process(request): from django.contrib.sites.models import Site from accounts.models import ContactUsInfo if Site.object... 阅读全文

posted @ 2015-01-18 14:36 颓废的悠然 阅读(362) 评论(0) 推荐(0)

django virtualenv
摘要:1. virtualenvvirtualenv用于创建独立的Python环境,多个Python相互独立,互不影响,它能够:1. 在没有权限的情况下安装新套件2. 不同应用可以使用不同的套件版本3. 套件升级不影响其他应用4.多个开发环境,一个需要django1.5,一个要1.6,另一个要django... 阅读全文

posted @ 2015-01-12 15:55 颓废的悠然 阅读(414) 评论(0) 推荐(0)

捕捉攻击者
摘要:pip install django-admin-honeypotAdd admin_honeypot to INSTALLED_APPSurl(r'^admin/', include('admin_honeypot.urls', namespace='admin_honeypot')),url(r... 阅读全文

posted @ 2015-01-08 16:05 颓废的悠然 阅读(253) 评论(0) 推荐(0)

django user模块改写
摘要:示例一:继承AbstractBaseUser,AbstractBaseUser只有三个字段password,last_login,is_active,以及需要复习的两个方法def get_full_name(self): raise NotImplementedError()def g... 阅读全文

posted @ 2015-01-08 14:05 颓废的悠然 阅读(888) 评论(0) 推荐(0)

Basic REST API Design
摘要: 阅读全文

posted @ 2015-01-08 13:58 颓废的悠然 阅读(111) 评论(0) 推荐(0)

{% load staticfiles %}
摘要:原先写法{# #}不使用路径写法,方便settings改配置static写法{% load staticfiles %}{%block%}里如果要继承上述文件可以使用{{block.super}} 阅读全文

posted @ 2015-01-08 10:13 颓废的悠然 阅读(10369) 评论(0) 推荐(0)

select_related
摘要:作用:减少DB访问次数from django.db import modelsclass Blog(models.Model): name = models.CharField(max_length=100) tagline = models.TextField() def __s... 阅读全文

posted @ 2015-01-07 22:28 颓废的悠然 阅读(795) 评论(0) 推荐(0)

django cbv
摘要:django 提供了一系列现成的类视图,他们都继承自一个 View 基类(django.views.generic.base.View)。在这个基类里实现了与 URLs 的接口(as_view)、请求方法匹配(dispatch)和一些其他的基本功能。比如 RedirectView 实现了一个简单的 ... 阅读全文

posted @ 2015-01-06 15:08 颓废的悠然 阅读(540) 评论(0) 推荐(0)

django最佳实践
摘要:导入的时候使用绝对导入或者清晰的相对导入相对导入用法:from __future__ import absolute_importfrom .models import what_u_need而不是form model import what_u_nedd在python 2.x中也使字符串采用3.x... 阅读全文

posted @ 2015-01-04 14:15 颓废的悠然 阅读(320) 评论(0) 推荐(0)

scrapy
摘要:scrapy extract提取出的是list,且selectors返回list.创建项目:scrapy startproject myproject下载内容并送到标准输出:scrapy fetch --nolog http://www.example.com/some/page.htmlscrap... 阅读全文

posted @ 2015-01-04 11:33 颓废的悠然 阅读(530) 评论(0) 推荐(0)

urlretrieve
摘要:urllib.urlretrieve(url[, filename[, reporthook[, data]]])参数说明:url:外部或者本地urlfilename:指定了保存到本地的路径(如果未指定该参数,urllib会生成一个临时文件来保存数据);reporthook:是一个回调函数,当连接上... 阅读全文

posted @ 2014-12-30 15:57 颓废的悠然 阅读(388) 评论(0) 推荐(0)

1 2 3 4 下一页

导航