摘要:
get_object_or_404() 是通过调用get()方法从model管理器上获取数据, 如果对象不存在,它会报Http404的异常,而不是model的 DoseNotExist异常。 get_list_or_404() 则是返回 model管理器的filter()方法后,转化成List后的结 阅读全文
摘要:
get_object_or_404() 是通过调用get()方法从model管理器上获取数据, 如果对象不存在,它会报Http404的异常,而不是model的 DoseNotExist异常。 get_list_or_404() 则是返回 model管理器的filter()方法后,转化成List后的结 阅读全文
摘要:
Teach Yourself Programming in Ten Years Peter Norvig Why is everyone in such a rush? Walk into any bookstore, and you'll see how to Teach Yourself Jav 阅读全文
摘要:
RedirectView作用是重定向一个指定,给定的Url.这个给定的Url可能包含有字典风格的字符串,因为关键字(词)会被改变,所以从这个Url中捕获的参数可能也会被修改,例如,Url中的“%”应该写成“%%”这样python才会将其修改成“%”。 如果指定的Url是None,那么会触发:Http 阅读全文
摘要:
主要功能是渲染模板,看官例: from django.views.generic.base import TemplateView from articles.models import Article class HomePageView(TemplateView): template_name 阅读全文
摘要:
class django.views.generic.base.View 它是基类的基类,其它View基类都是从这继承的。 官例: 属性: 1.http_method_names: 这个视图类接受的http方法的列表,默认情况是:['get', 'post', 'put', 'patch', 'de 阅读全文
摘要:
之前学了abstract,这是后续的一些options app_label: app_label的作用是:如果一个model定义不在INSTALLED_APPS中,那么此时就需要声明,这个model的属于哪个app,例如:app_label="myapp" db_table: 这个在之前的那个abs 阅读全文
摘要:
当abstract=True时,这个model就变成了abstrct base class,那这个基类有什么特性呢? 当某一model中设置了abstract=True时,就会使该model中的字段都不会产生对应的表,而是可以作为基类加入到其他model中 那有什么用呢? 有时多个model有些相同 阅读全文
摘要:
shortcut function都在django.shortcuts这个包中,主要包含有:render(), render_to_response(), redirect(), get_objects_or_404(), get_list_or_404() 1. render(request, t 阅读全文
摘要:
decorators(装饰器) 1. require_http_methods 在django.views.decorators.http中,可以用来限制请求的权限。 require_http_methods(request_method_list), 这样只有request_method_list 阅读全文
摘要:
on_delete指的是通过ForeignKey连接起来的对象被删除后,当前字段怎么变化。 常见的选项有: models.CASCADE,对就对象删除后,包含ForeignKey的字段也会被删除 models.PROTECT,删除时会引起ProtectedError models.SET_NULL, 阅读全文
|