doc:appunti:prog:django
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
doc:appunti:prog:django [2011/06/26 11:07] – [Mettere i dati nella vista] niccolo | doc:appunti:prog:django [2011/06/26 11:49] – [Mettere i dati nella vista] niccolo | ||
---|---|---|---|
Line 165: | Line 165: | ||
</ | </ | ||
''' | ''' | ||
- | u'Balance' | + | u'Titolo della vista' |
) | ) | ||
return HttpResponse(output) | return HttpResponse(output) | ||
Line 187: | Line 187: | ||
Invece di includere il codice HTML direttamente nella vista (funzione Python) si utilizza il sistema dei **template**. | Invece di includere il codice HTML direttamente nella vista (funzione Python) si utilizza il sistema dei **template**. | ||
- | Nella directory radice del progetto si crea la sottodirectory **'' | + | Nella directory radice del progetto si crea la sottodirectory **'' |
<code python> | <code python> | ||
+ | import os.path | ||
+ | |||
TEMPLATE_DIRS = ( | TEMPLATE_DIRS = ( | ||
os.path.join(os.path.dirname(__file__), | os.path.join(os.path.dirname(__file__), | ||
Line 195: | Line 197: | ||
</ | </ | ||
- | Quindi si crea il file **'' | + | Quindi si crea il file **'' |
<code html> | <code html> | ||
Line 209: | Line 211: | ||
<code python> | <code python> | ||
+ | from django.http import HttpResponse | ||
+ | from django.template import Context | ||
+ | from django.template.loader import get_template | ||
+ | def my_view(request): | ||
+ | template = get_template(' | ||
+ | variables = Context({ | ||
+ | ' | ||
+ | ' | ||
+ | }) | ||
+ | output = template.render(variables) | ||
+ | return HttpResponse(output) | ||
</ | </ | ||
+ | |||
+ | FIXME Da fare: | ||
+ | |||
+ | * Aggiungere nella vista l' | ||
+ | * Aggiungere nel template l' | ||
+ | * Trovare il modo per mostrare i dati aggregati (somma di un campo, ecc.). | ||
===== Webserver di test ===== | ===== Webserver di test ===== | ||
doc/appunti/prog/django.txt · Last modified: 2011/06/28 09:15 by niccolo