This document discusses several key aspects of Django including:
1) Adding 'django.contrib.admin' to INSTALLED_APPS and using ModelAdmin objects and the @admin.register decorator to register models with the admin interface.
2) How Django processes requests by matching URLs and calling associated views which are Python functions.
3) Common functions for rendering templates like render(), render_to_response(), and redirect().
4) Working with HTTP forms using the Form class, rendering forms in templates, and options for bound/unbound forms.
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
130 views
Django Admin
This document discusses several key aspects of Django including:
1) Adding 'django.contrib.admin' to INSTALLED_APPS and using ModelAdmin objects and the @admin.register decorator to register models with the admin interface.
2) How Django processes requests by matching URLs and calling associated views which are Python functions.
3) Common functions for rendering templates like render(), render_to_response(), and redirect().
4) Working with HTTP forms using the Form class, rendering forms in templates, and options for bound/unbound forms.
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14
'django.contrib.
admin’ should be add in
INSTALLED_APPS Determinine which of your MODEL should be in your admin interface ModelAdmin objects The register decorator @admin.register(<Model>) @admin.register(<mode1>, <model2>, ..site=custome_model> Model Admin Options: ModelAdmin.actions/ModelAdmin.adtion_on_top/ModelAdmi n.action_on_bottom date_hierarchy ( date_hierarchy=‘<field name>’ ) empty_value_display (empty_value_display =‘string name’ ) exclude Fields / fieldsets Classes filter_horizontal/ filter_vertical A python callable view It takes the request object and respond accordingly ROOT_URLCONF How Django processes a request ◦ django.conf.urls.url() ◦ Django runs through each URL pattern, in order, and stops at the first one that matches the requested URL ◦ Once one of the regexes matches, Django imports and calls the given view, which is a simple Python function (or a class-based view). The view gets passed the following arguments: An instance of HttpRequest. If the matched regular expression returned no named groups, then the matches from the regular expression are provided as positional arguments. The keyword arguments are made up of any named groups matched by the regular expression, overridden by any arguments specified in the optional kwargs argument to django.conf.urls.url(). render(request, template_name, context=Non e, content_type=None, status=None, using= None) render_to_response(template_name, context =None, content_type=None, status=None, us ing=None) redirect(to, permanent=False, *args, **kwarg s) HTTP Forms ◦ Form, action, method Form class ◦ Django.forms.Form Form templates ◦ {{ form }} Bound & UnBound form instances Rendering fields manually Form rendering options ◦ Form as table, form as <p>, form as ul Rendering form error messages Reusable form templtes. ◦ Include “form.html” Formsets