djangopython powered MVC framework
Presentation topics● why python and why django?● what is MVC?● the M in the django framework● the V in the django framewor...
why python and why django?#1, why python? ● python is a "natural" OO language; ● python has functional capabilities; ● "ba...
what is MVC?A software development pattern where the business logic isseparated from the UI.In web development: ● (M)odel:...
what is MVC?In the Django framework, things are a little bit different...                      Welcome to "MTV"!!         ...
the M in the django framework
the M in the django frameworkNot much different from the other M... ● It holds the business logic/rules; ● It is related w...
the M in the django frameworkExample:from django.db import modelsclass Company(models.Model):    name = models.CharField(_...
the V in the django framework
the V in the django frameworkA view, in django, has two parts:#1 A callback that: ● is a normal python method that always ...
the V in the django framework#2 An URLconf: ● that is a mapper between urls and the view callbacks; ● that is described by...
the V in the django frameworkWe can also include the templates here, since it is intrinsicallylinked to the view callbacks...
the V in the django frameworkExample of a view:from django.shortcuts import render_to_responsedef property_details(request...
the V in the django frameworkExample of a template:{% extends "base.html" %}{% load i18n %}{% block highlights %}{% includ...
the C in the django framework
the C in the django frameworkPossibly the most complex part... Basically its all the djangoframework! This includes: ● mod...
django admin
django admindjango admin is a very usefull app that allows you to save a lotof time. ● Uses class attributes to create for...
django adminDefault objects list
django adminDefault add form
Upcoming SlideShare
Loading in …5
×

A gentle intro to the Django Framework

2,403 views

Published on

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,403
On SlideShare
0
From Embeds
0
Number of Embeds
68
Actions
Shares
0
Downloads
40
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

A gentle intro to the Django Framework

  1. 1. djangopython powered MVC framework
  2. 2. Presentation topics● why python and why django?● what is MVC?● the M in the django framework● the V in the django framework● and the C in the django framework● django admin
  3. 3. why python and why django?#1, why python? ● python is a "natural" OO language; ● python has functional capabilities; ● "batteries included"!!#2, why django? ● uses python (ahhh!); ● interfaces for common actions (dry); ● pluggable apps; ● you have more time to CREATE! ● you had VALUE to you products;
  4. 4. what is MVC?A software development pattern where the business logic isseparated from the UI.In web development: ● (M)odel: the business logic/rules off the application (mostly the DB); ● (V)iew: the (x)html rendered and presented to the user; ● (C)ontroller: the handler that receives GET or POST requests, works over the domain object and retrieves a response to the user;
  5. 5. what is MVC?In the Django framework, things are a little bit different... Welcome to "MTV"!! (Model - Template - View)
  6. 6. the M in the django framework
  7. 7. the M in the django frameworkNot much different from the other M... ● It holds the business logic/rules; ● It is related with the DB; ● Describes the DB as classes of objects using a mapper (ORM); ● It holds methods to retrieve data;
  8. 8. the M in the django frameworkExample:from django.db import modelsclass Company(models.Model): name = models.CharField(_("Company name"), max_length=64) phone = models.CharField("URL", max_length=32) fax = models.CharField("Fax", max_length=32, null=True, blank=True) email = models.EmailField("E-mail", max_length=32, null=True, blank=True) ceos = models.ForeignKey(entities.Ceo) class Meta: ordering = [name] db_table = company verbose_name = _(Company) verbose_name_plural = _(Companies) # Return companys administrators def get_ceos(self): return self.ceos # Returns an instance in a human-readable format def __unicode__(self): return self.name
  9. 9. the V in the django framework
  10. 10. the V in the django frameworkA view, in django, has two parts:#1 A callback that: ● is a normal python method that always receive an HTTP request object... ● ... and always returns an HTTP response object; ● describes which data is presented;
  11. 11. the V in the django framework#2 An URLconf: ● that is a mapper between urls and the view callbacks; ● that is described by regexes;
  12. 12. the V in the django frameworkWe can also include the templates here, since it is intrinsicallylinked to the view callbacks. ● Django has its own template system/language; ● It is pythonic, but very stricted; ● Organized by tags; ● Focus on how you display data; ● You can write your own set of tags;
  13. 13. the V in the django frameworkExample of a view:from django.shortcuts import render_to_responsedef property_details(request, id): try: c = {} c.update(csrf(request)) property = Property.objects.get(pk=id) c[property] = property except Property.DoesNotExist: raise Http404 return render_to_response(properties/property_details.html, c)Example of an URLconf:urlpatterns = patterns(properties.views, (r^(?P<id>d+[a-z]*), property_details),)
  14. 14. the V in the django frameworkExample of a template:{% extends "base.html" %}{% load i18n %}{% block highlights %}{% include "horizontal_search.html" %}<div style="margin-top: 25px;"></div>{% endblock %}{% block content %} <div style="padding-left: 9px; padding-right: 6px;"> <div id="text_wrapper"><h4>{% trans "About" %} {{ property.reference }}</h4>{{ property.description }} </div>{% endblock %}
  15. 15. the C in the django framework
  16. 16. the C in the django frameworkPossibly the most complex part... Basically its all the djangoframework! This includes: ● modules that are responsible for user authentication... ● modules that prevents CSRFs... ● that are responsible for the website language (i18n, l7n); ● etc...Its all the machinery between an URLconf and a view. Thosemodules are called middleware.
  17. 17. django admin
  18. 18. django admindjango admin is a very usefull app that allows you to save a lotof time. ● Uses class attributes to create forms; ● Common methods included (add, edit, remove); ● Complete admin interface that can be changed; ● User management;
  19. 19. django adminDefault objects list
  20. 20. django adminDefault add form

×