mirror of
				https://github.com/django/django.git
				synced 2025-10-31 01:25:32 +00:00 
			
		
		
		
	MERGED MAGIC-REMOVAL BRANCH TO TRUNK. This change is highly backwards-incompatible. Please read http://code.djangoproject.com/wiki/RemovingTheMagic for upgrade instructions.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@2809 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
		
							
								
								
									
										23
									
								
								django/shortcuts/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								django/shortcuts/__init__.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,23 @@ | ||||
| # This module collects helper functions and classes that "span" multiple levels | ||||
| # of MVC. In other words, these functions/classes introduce controlled coupling | ||||
| # for convenience's sake. | ||||
|  | ||||
| from django.template import loader | ||||
| from django.http import HttpResponse, Http404 | ||||
|  | ||||
|  | ||||
| def render_to_response(*args, **kwargs): | ||||
|     return HttpResponse(loader.render_to_string(*args, **kwargs)) | ||||
| load_and_render = render_to_response # For backwards compatibility. | ||||
|  | ||||
| def get_object_or_404(klass, **kwargs): | ||||
|     try: | ||||
|         return klass._default_manager.get(**kwargs) | ||||
|     except klass.DoesNotExist: | ||||
|         raise Http404 | ||||
|  | ||||
| def get_list_or_404(klass, **kwargs): | ||||
|     obj_list = list(klass._default_manager.filter(**kwargs)) | ||||
|     if not obj_list: | ||||
|         raise Http404 | ||||
|     return obj_list | ||||
		Reference in New Issue
	
	Block a user