Differences between revisions 3 and 4
Revision 3 as of 2009-02-24 13:09:50
Size: 685
Editor: 147
Comment:
Revision 4 as of 2009-02-24 13:12:03
Size: 684
Editor: 147
Comment:
Deletions are marked like this. Additions are marked like this.
Line 16: Line 16:
 1. Skúste http://localhost:8000/hello/moon/sun . Prerobte to tak,
aby funkcia {{{view.hello}} vypísala iba '''Hello, moon.'''
 1. Skúste http://localhost:8000/hello/moon/sun . Prerobte to tak, aby funkcia {{{view.hello}} vypísala iba '''Hello, moon.'''

Hello world V2

  • Vezmeme projekt hello a prerobíme ho tak, aby napr URL

http://localhost:8000/hello/moon/ napísalo Hello, moon.

  • V urls.py zmeníme príslušný prvok urlpatterns takto:

   1     (r'^hello/(.*)/$', views.hello),

views.py bude takéto:

   1 from django.http import HttpResponse
   2 
   3 def hello(request,who):
   4     html="""<html>
   5     <body>
   6     <h1>Hello, """+who+"""</h1>
   7     </body>
   8     </html>
   9     """
  10     return(HttpResponse(html))
views.py

Úlohy

  1. Skúste http://localhost:8000/hello/moon/sun . Prerobte to tak, aby funkcia {view.hello vypísala iba Hello, moon.

  2. A teraz tak, aby vypísala Hello, moon and sun.

  3. A teraz chceme, aby to fungovalo všeobecne, t.j. napríklad http://localhost:8000/hello/a/b/c/ má vypísať Hello, a,b and c

KMaDGWiki: ProgramovanieInternetovychAplikacii/HelloWorld_V2 (last edited 2009-02-24 23:32:31 by 92)