7. The Framework:
What is Django?
Django is a great framework for building Web 2.0 applications!
It 'was designed to improve development time and quality.
http://www.djangoproject.org
4
9. MTV Pattern
“Model-Template-View”
A pattern that helps to separate the user interface level from
the other parts of the system.
Model - contains classes whose
instances represent the data to
display and manipulate.
Template - contains objects that
control and manage user interaction
with the model and view layers.
View - contains the objects used in the
UI to display the data in the model.
5
10. DBMS
“Database management system”
Some of the most well-known DBMS used in Django:
6
11. DBMS
“Database management system”
Some of the most well-known DBMS used in Django:
6
21. Creating a view
First Step
First of all combining a URL to a view
-> http://127.0.0.1:8000/hello
Open the file urls.py and insert the following string as the last
parameter:
-> (r’^hello/$’, “views.hello”)
11
22. Creating a view
First Step
First of all combining a URL to a view
-> http://127.0.0.1:8000/hello
Open the file urls.py and insert the following string as the last
parameter:
-> (r’^hello/$’, “views.hello”)
11
23. Creating a view
First Step
First of all combining a URL to a view
-> http://127.0.0.1:8000/hello
Open the file urls.py and insert the following string as the last
parameter:
-> (r’^hello/$’, “views.hello”)
Regular expression that
indicates the beginning
and the end of the URL.
11
24. Creating a view
First Step
First of all combining a URL to a view
-> http://127.0.0.1:8000/hello
Open the file urls.py and insert the following string as the last
parameter:
-> (r’^hello/$’, “views.hello”)
Regular expression that
indicates the beginning
and the end of the URL.
11
25. Creating a view
First Step
First of all combining a URL to a view
-> http://127.0.0.1:8000/hello
Open the file urls.py and insert the following string as the last
parameter:
-> (r’^hello/$’, “views.hello”)
Regular expression that
indicates the beginning Combining Url/Vista
and the end of the URL.
11
26. Creating a view
Second Step
The view is simply a Python method that returns the data.
In the root of the project we create the views.py file and insert the
following method:
from django.http import HttpResponse
def hello(request):
return HttpResponse(“Hello World”)
Now type in a terminal:
$ python manage.py runserver
12
29. Creating Applications
Is good practice to structure the project into sub-applications in
order to have greater control over the entire system to be
developed!
$ python manage.py startapp test
If there aren't errors in the root of the project should have a folder
named "test" with the following files inside
__init__.py
models.py
views.py
Inatalled_Apps indicate the presence in the settings.py file,
application "test" by simply inserting his name in quotes at the
bottom of the list.
14
30. Creating models
Change the models.py file in the folder "test "...
from django.db import models
class Persona (models.Model):
nome = models.CharField(max_length=50)
cognome = models.CharField(max_length=50)
def __unicode__(self):
return u"%s %s" % (self.nome, self.cognome)
class Meta:
verbose_name_plural ="Persone"
15
31. Add a Database
Edit the settings.py file in the following way:
DATABASES = {
'default': {
'ENGINE': 'sqlite3', #NAME del dbms es (oracle, mysql etc..)
'NAME': 'test.db', #DB NAME
'USER': '', #USERNAME
'PASSWORD': '', #Password
'HOST': '', #DMBS ADDRESS
'PORT': '', #PORT
}
}
16
34. ORM
“Object-Relational Mapping”
An ORM is a kind of linker between
objects and relational databases.
Through this linker the created objects
with a high-level language are
included in the relational database.
17
35. ORM
“Object-Relational Mapping”
An ORM is a kind of linker between
objects and relational databases.
Through this linker the created objects
with a high-level language are
included in the relational database.
17
36. ORM
“Object-Relational Mapping”
An ORM is a kind of linker between
objects and relational databases.
Through this linker the created objects
with a high-level language are
included in the relational database.
17
37. ORM
“Object-Relational Mapping”
An ORM is a kind of linker between
objects and relational databases.
Through this linker the created objects
with a high-level language are
included in the relational database.
$ python manage.py syncdb
17
38. Creating Admin Panel
First Step
Open the file settings.py INSTALLED_APPS and insert in the
application for the board of directors as follows:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
)
18
39. Creating Admin Panel
Second Step
Associate a URL to the application, then edit the urls.py file as
follows:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^admin/', include(admin.site.urls)),
(r'^hello/$', "views.hello"),
)
19
40. Creating Admin Panel
Second Step
Associate a URL to the application, then edit the urls.py file as
follows:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
!
(r'^admin/', include(admin.site.urls)),
là
(r'^hello/$', "views.hello"),
oi
)
E t V
19
43. URL
Uniform Resource Locator
Benefit of having "ordered" URL
- Easy to remember
- Palatability by search engines
- Durable
Example:
1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17
2) http://nomedominio.com/blog
21
44. URL
Uniform Resource Locator
Benefit of having "ordered" URL
- Easy to remember
- Palatability by search engines
- Durable
Example:
1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17
2) http://nomedominio.com/blog
21
45. URL
Uniform Resource Locator
Benefit of having "ordered" URL
- Easy to remember
- Palatability by search engines
- Durable
Example:
1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17
2) http://nomedominio.com/blog
21
46. URL
Uniform Resource Locator
Benefit of having "ordered" URL
- Easy to remember
- Palatability by search engines
- Durable n g!
yi
r rif
Ho
Example:
1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17
2) http://nomedominio.com/blog
21
47. URL
Uniform Resource Locator
Benefit of having "ordered" URL
- Easy to remember
- Palatability by search engines
- Durable n g!
yi
r rif
Ho
Example:
1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17
2) http://nomedominio.com/blog
21
48. URL
Uniform Resource Locator
Benefit of having "ordered" URL
- Easy to remember
- Palatability by search engines
- Durable n g!
yi
r rif
Ho
Example:
1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17
2) http://nomedominio.com/blog
to
be
rep
lac
ed
21
49. URL
Uniform Resource Locator
Benefit of having "ordered" URL
- Easy to remember
- Palatability by search engines
- Durable n g!
yi
r rif
Ho
Example:
1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17
2) http://nomedominio.com/blog
to
be
rep
lac
ed
21
50. URL
Uniform Resource Locator
Benefit of having "ordered" URL
- Easy to remember
- Palatability by search engines
- Durable n g!
yi
r rif
Ho
Example:
1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17
2) http://nomedominio.com/blog
to
be
rep
lac
ed
21
51. URL
Uniform Resource Locator
Benefit of having "ordered" URL
- Easy to remember
- Palatability by search engines
- Durable n g!
yi
r rif
Ho
Example:
1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17
2) http://nomedominio.com/blog
to
be
rep
lac
ed
21
52. URL
Uniform Resource Locator
Benefit of having "ordered" URL
- Easy to remember
- Palatability by search engines
- Durable n g!
yi
r rif
Ho
Example:
1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17
2) http://nomedominio.com/blog
to
be
rep
lac
ed
21
53. URL
Uniform Resource Locator
Benefit of having "ordered" URL
- Easy to remember
- Palatability by search engines
- Durable n g!
yi
r rif
Ho
Example:
1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17
2) http://nomedominio.com/blog
to
be
rep
lac
ed
21
54. URL
Uniform Resource Locator
Benefit of having "ordered" URL
- Easy to remember
- Palatability by search engines
- Durable n g!
yi
r rif
Ho
Example:
1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17
2) http://nomedominio.com/blog
to
be
rep
lac
ed
21
55. Creating URL
To create a URL like the following
-> http://127.0.0.1:8000/hello
you have to combine the view of the URL, so, you have to open the
file urls.py and insert the following string as the last parameter:
-> (r’^hello/$’, “views.hello”)
22
56. Creating URL
To create a URL like the following
-> http://127.0.0.1:8000/hello
you have to combine the view of the URL, so, you have to open the
file urls.py and insert the following string as the last parameter:
-> (r’^hello/$’, “views.hello”)
22
57. Creating URL
To create a URL like the following
-> http://127.0.0.1:8000/hello
you have to combine the view of the URL, so, you have to open the
file urls.py and insert the following string as the last parameter:
-> (r’^hello/$’, “views.hello”)
22
58. Creating URL
To create a URL like the following
-> http://127.0.0.1:8000/hello
you have to combine the view of the URL, so, you have to open the
file urls.py and insert the following string as the last parameter:
-> (r’^hello/$’, “views.hello”)
Regular expression that
indicates the beginning
and the end of the URL.
22
59. Creating URL
To create a URL like the following
-> http://127.0.0.1:8000/hello
you have to combine the view of the URL, so, you have to open the
file urls.py and insert the following string as the last parameter:
-> (r’^hello/$’, “views.hello”)
Regular expression that
indicates the beginning Combining Url/Vista
and the end of the URL.
22