Django-2
来源:互联网 发布:淘宝上没有京东 编辑:程序博客网 时间:2024/05/22 14:51
urlpatterns = patterns('', url(r'^archive/$', 'mysite.views.archive', {'blogid': 3}), url(r'^about/$', 'mysite.views.about', {'blogid': 3}),)
the {'blogid':3} is the third parameter
def url(regex, view, kwargs=None, name=None, prefix=''):
and further pass into return object
RegexURLPattern(regex, view, kwargs, name)
then it will be the default_args of
class RegexURLPattern(LocaleRegexProvider): def __init__(self, regex, callback, default_args=None, name=None): LocaleRegexProvider.__init__(self, regex)
then in get_response function, it will retrieve the value as **callback_kwargs
response = callback(request, *callback_args, **callback_kwargs)
=================================
In setting.spy, if we set DEBUG to False , we must set ALLOWED_HOSTS to a valid server. Otherwise 500 error will return .
=================================
When raise Http404 in view function definition, what will happen?
URL resolover will call , with view_type is 404, self.urlconf_module is urls.py under proejct
def _resolve_special(self, view_type): callback = getattr(self.urlconf_module, 'handler%s' % view_type, None) if not callback: # No handler specified in file; use default # Lazy import, since django.urls imports this file from django.conf import urls callback = getattr(urls, 'handler%s' % view_type) return get_callable(callback), {}
so if urls.py has no definition of 'handler404', it will search 'django.conf.urls', and the module has function
django.views.defaults.page_not_found as handler, with default template name 404.html
==========
if we define such function in urls.py under project
def handler404(*args, **kwargs): pass
the code will go to here, instead of default function mentioned above
the system also has a function named def handle_uncaught_exception(self, request, resolver, exc_info):
it will also try to find 500 error handler like 404 mentioned above
- Django-2
- django 2
- django-2:django开发初探
- 【Django tutorial 2】
- django模型2
- Django项目2
- Django笔记2
- django入门笔记-2
- Django 学习笔记(2)
- Django学习笔记2
- django源码笔记-【2】
- 浅析django form(2)
- django notes 2
- Django开发综述2
- Django基础学习<2>
- Django学习笔记2
- django自学2
- Django学习笔记2
- HDU 4082Hou Yi's secret2011北京现场赛B题(统计相似三角形个数)
- windows程序设计中的 VirtualAlloc
- 10步让你成为更优秀的程序员
- a2dp
- 国外IT网站
- Django-2
- [ios]关于tablelist里的每个按钮点击时传值的问题讨论
- 想成为Java高手的25个学习目标
- Android NDK下面如何使用zlib的库
- 用uaac注册dashboard用户
- 查看SAP数据里面存储长度
- Android有效解决加载大图片时内存溢出的问题
- C语言的谜题
- LeetCode - N-Queens II