21.01.2015 Views

color version - PET: Python Entre Todos - Python Argentina

color version - PET: Python Entre Todos - Python Argentina

color version - PET: Python Entre Todos - Python Argentina

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

is needed to get an application that provides functionality to administer the database’s<br />

content Logically, screens (pages).<br />

Well, Django’s Admin is exactly that. We simply tell it something like “hey, admin! Look,<br />

here I told that I had customers in the database, can you give me a customer’s CRUD”.<br />

And the Admin will do just that. It’s that simple (if you don’t believe me, check the code<br />

of Django’s tutorial).<br />

[CRUD is an application that allows you to Create, Read, Update and Delete]<br />

We can even customize the way those forms are shown so that we can add filters on<br />

fields of our choice, decide what columns to show in lists, how to show fields when<br />

editing, etc.<br />

This application is of great use to us developers during the creation of the site to add<br />

content and get previews. It is also useful in production for the site’s administrators or<br />

moderators. But it can also be of use to the end user, depending on the case.<br />

Every time I see the admin, I regret the hours I devoted to developing CRUDs that are<br />

not a fraction as configurable as Django’s :)<br />

It is easier than it looks:<br />

1. The user asks for a URL (“I want to get http://news.com/crimes really fast!”)<br />

2. Django realizes that to serve that URL needs to call a function (a view from now on).<br />

As you imagine, it does call it.<br />

3. In our view (the function “cops” for example), we get the news from our database that<br />

are categorized as related to cops.<br />

4. Finally, our view will tell Django to return to the user a specific template (in this case,<br />

the HTML of the cops page) but using the data we provide within the template.<br />

Making it all work<br />

Well, we have now gone through a few interesting things Django includes. The question<br />

now is: how do we put all these things together<br />

So far we have a general idea of how it works and how to work with Django, but it can be<br />

understood a lot better if we see it with code. It is for that reason that I recommend the<br />

official Django tutorial that you can find at<br />

http://docs.djangoproject.com/en/dev/intro/tutorial01/<br />

In the tutorial, you can see how to build a simple application from scratch. With what you<br />

read in this article it will surely be even easier to understand what you will be doing<br />

there.<br />

And if it is not easier, you have my mail to complain :)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!