摘要: 视图 用途:把复杂重用率高的sql语句编写成sql视图,提供接口给app调用,实现解耦。 语法: create VIEW 视图名 as SQL语句 例子: create view teacher_view as select tid from teacher where tname='李平老师'; 阅读全文
posted @ 2018-10-02 13:01 Super-Yan 阅读(169) 评论(0) 推荐(0)
摘要: HttpRequest objects 属性 HttpRequest.scheme 表示请求协议的字符串(通常是http或https)。 HttpRequest.body 原始HTTP请求主体作为字节字符串。这对于以不同于传统HTML表单的方式处理数据非常有用:二进制图像、XML有效负载等。对于处理 阅读全文
posted @ 2018-10-02 12:58 Super-Yan 阅读(189) 评论(0) 推荐(0)
摘要: 文件上传 使用form表单类的上传 forms.py from django import forms class UploadFileForm(forms.Form): title = forms.CharField(max_length=50) file = forms.FileField() 阅读全文
posted @ 2018-10-02 12:58 Super-Yan 阅读(398) 评论(0) 推荐(0)
摘要: Django提供了几个可以应用于视图以支持各种HTTP特性的装饰器 Allowed HTTP django.views.decorators.http里的装饰器可以根据请求方法限制对视图的访问。 require_http_methods 接收特定的HTPP 请求方法 from django.view 阅读全文
posted @ 2018-10-02 12:57 Super-Yan 阅读(522) 评论(0) 推荐(0)
摘要: render() render(request, template_name, context=None, content_type=None, status=None, using=None) 必须参数 request:视图接受到的request template_name:模板名称 可选参数 c 阅读全文
posted @ 2018-10-02 12:57 Super-Yan 阅读(173) 评论(0) 推荐(0)
摘要: view function 的几种返回值 1. return HttpResponse(html) 2. return HttpResponseNotFound(html) 3. raise Http404("Poll does not exist") 定制:在template tree顶层编写40 阅读全文
posted @ 2018-10-02 12:56 Super-Yan 阅读(104) 评论(0) 推荐(0)
摘要: View执行步骤 1. 查找setting.py中的ROOT_URLCONF,跳到对应urls 查找urls.py中的urlpatterns,按顺序依次匹配 返回匹配上的view 如果没匹配上,报错 Example from django.urls import path from . import 阅读全文
posted @ 2018-10-02 12:56 Super-Yan 阅读(224) 评论(0) 推荐(0)
摘要: Conditional Expressions建立一些逻辑关系 The conditional expression classes from django.db import models class Client(models.Model): REGULAR = 'R' GOLD = 'G' P 阅读全文
posted @ 2018-10-02 12:55 Super-Yan 阅读(143) 评论(0) 推荐(0)
摘要: from django.db.functions import ... Cast() 转换类型 value = Value.objects.annotate(field_as_float=Cast('integer', FloatField())).get() print(value.field_a 阅读全文
posted @ 2018-10-02 12:54 Super-Yan 阅读(342) 评论(0) 推荐(0)
摘要: Custom Lookups 一个简单LookUp例子 Author.objects.filter(name__ne='Jack') Translate SQL "author"."name" 'Jack' 自定义 from django.db.models import Lookup from d 阅读全文
posted @ 2018-10-02 12:53 Super-Yan 阅读(236) 评论(0) 推荐(0)