Your SlideShare is downloading. ×
0
Django
                qingfeng@douban.com




2010   8   29
Django?



2010   8   29
,Web   发   动




                       3
2010   8   29
4
2010   8   29
过   Django       web
                             东




                         5
2010   8   29
达   这   Django           Web 发
                                     业




                                 6
2010   8   29
“   ”




                    7
2010   8   29
时 Django
                           framework       发




                                       8
2010   8   29
Django    &历

                • M-T-V
                •
                • DRY
                • Unix    艺术



2010   8   29
Django

                • startproject [project_name]
                • startapp [app_name]
                • write urls,v...
•
                •   统

                •    发

                •        跃

                •            ....



2010   8...
Django 录




2010   8   29
M



2010   8   29
Lyrics.objects.get_user_lyrics(uid)
                        lyrics.get_creator()




2010   8   29
页




2010   8   29
Lyrics.object.all()
                发   SQL   ,     历     发   询




2010   8   29
l=Lyrics.object.get(id=10)
                song = l.song -> [发 SQL]
                           join   SQL




2010   8   29
2010   8   29
luzong/



2010   8   29
单



2010   8   29
def test_user_profile(self):
                  people = self.client.GetPeople('/people/qingfeng')
                  self.as...
T+V



2010   8   29
Generic Views



2010   8   29
urlpatterns += patterns('django.views.generic',
               ('^about/$', 'simple.direct_to_template',{'template':'about...
views.py
                  zero!


2010   8   29
Demo



2010   8   29
V
                    def index(request):
                      news = News.objects.order_by('-pub_date')[:3]
            ...
views   过   ?



2010   8   29
inclusion_tag



2010   8   29
@register.inclusion_tag('mods/home_user_info.html')
                def show_home_user_info(user_id):
                  .....
Template tag



2010   8   29
24



2010   8   29
for,if,ifequal....



2010   8   29
{% for o in some_list %}
                  <tr class="{% cycle 'row1' 'row2' %}">
                     ...
               ...
Template filter



2010   8   29
30+



2010   8   29
{{ value|linebreaksbr }}



2010   8   29
{{ value|linenumbers }}
                         1. one
                         2. two
                         3. three
...
{{ value|random }}
                      [a,b,c,d]->b




2010   8   29
{{ value|title }}
                "my first post"->"My First Post"




2010   8   29
tag &filter




2010   8   29
@register.filter
                def join_list(arr):
                  return ",".join(arr)




2010   8   29
,




2010   8   29
2010   8   29
页
       http://docs.djangoproject.com/en/1.1/topics/pagination/




2010   8   29
contact_list = Contacts.objects.all()
                paginator = Paginator(contact_list, 25) # Show 25




2010   8   29
from django.core.paginator import Paginator, InvalidPage,
                EmptyPage

                def listing(request):...
{% for contact in contacts.object_list %}
                    {# Each "contact" is a Contact model object. #}
            ...
Middleware




2010   8   29
OpenID



2010   8   29
Django Auth



2010   8   29
AUTHENTICATION_BACKENDS= (
                  'django.contrib.auth.backends.RemoteUserBackend',
                )

        ...
Cache



2010   8   29
CACHE_BACKEND='redis_cache.cache://127.0.0.1:6379'
                CACHE_BACKEND='memcached://127.0.0.1:6379'


          ...
统



2010   8   29
./manage.py [xxx]



2010   8   29
统



2010   8   29
settings.py



2010   8   29
i18n



2010   8   29
ETag,Last-Modified



2010   8   29
2010   8   29
django debug toolbar



2010   8   29
2010   8   29
2010   8   29
django extensions
       http://github.com/django-extensions/django-extensions




2010   8   29
Django Admin



2010   8   29
2010   8   29
2010   8   29
2010   8   29
2010   8   29
Django

                •        .....

                •
                •     Django 发   业   统




2010   8   29
Django

                •   http://bitbucket.org/qingfeng/django_genericview_wiki/

                •       4

           ...
----   风




2010   8   29
Upcoming SlideShare
Loading in...5
×

Django

1,095

Published on

Django入门讲座

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

No Downloads
Views
Total Views
1,095
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
18
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Transcript of "Django"

  1. 1. Django qingfeng@douban.com 2010 8 29
  2. 2. Django? 2010 8 29
  3. 3. ,Web 发 动 3 2010 8 29
  4. 4. 4 2010 8 29
  5. 5. 过 Django web 东 5 2010 8 29
  6. 6. 达 这 Django Web 发 业 6 2010 8 29
  7. 7. “ ” 7 2010 8 29
  8. 8. 时 Django framework 发 8 2010 8 29
  9. 9. Django &历 • M-T-V • • DRY • Unix 艺术 2010 8 29
  10. 10. Django • startproject [project_name] • startapp [app_name] • write urls,views 2010 8 29
  11. 11. • • 统 • 发 • 跃 • .... 2010 8 29
  12. 12. Django 录 2010 8 29
  13. 13. M 2010 8 29
  14. 14. Lyrics.objects.get_user_lyrics(uid) lyrics.get_creator() 2010 8 29
  15. 15. 页 2010 8 29
  16. 16. Lyrics.object.all() 发 SQL , 历 发 询 2010 8 29
  17. 17. l=Lyrics.object.get(id=10) song = l.song -> [发 SQL] join SQL 2010 8 29
  18. 18. 2010 8 29
  19. 19. luzong/ 2010 8 29
  20. 20. 单 2010 8 29
  21. 21. def test_user_profile(self): people = self.client.GetPeople('/people/qingfeng') self.assertEqual(people.uid.text,'qingfeng') purl = 'http://t.douban.com/icon/u1001560-12.jpg' self.assertEqual(people.link[2].href,purl) 2010 8 29
  22. 22. T+V 2010 8 29
  23. 23. Generic Views 2010 8 29
  24. 24. urlpatterns += patterns('django.views.generic', ('^about/$', 'simple.direct_to_template',{'template':'about.html'}), url(r'^page/(?P<object_id>d+)/$', 'list_detail.object_detail', info, name='detail_page'), url(r'^page/$', 'list_detail.object_list', {"queryset":Page.objects.all(),"paginate_by":3}, name='list_page'), url(r'^page/create/$', 'create_update.create_object', model, name='create_page'), url(r'^page/update/(?P<object_id>d+)/$', 'create_update.update_object', model, name='update_page'), url(r'^page/delete/(?P<object_id>d+)/$', 'create_update.delete_object', {"model":Page,"post_delete_redirect":"/page/"}, name='delete_page'), ) 2010 8 29
  25. 25. views.py zero! 2010 8 29
  26. 26. Demo 2010 8 29
  27. 27. V def index(request): news = News.objects.order_by('-pub_date')[:3] c = TCorner.objects.order_by('-pub_date')[:3] return render_to_response("index.html",locals()) T {% for i in news %} <div class="left_box"> {% url detail_page i.id as detail_page %} <h2><a href="{{detail_page}}">{{ i.new_title }}</a></h2> <p>{{ i.new_content|linebreaks }}</p> </div><hr color="olive"> {% endfor %} 2010 8 29
  28. 28. views 过 ? 2010 8 29
  29. 29. inclusion_tag 2010 8 29
  30. 30. @register.inclusion_tag('mods/home_user_info.html') def show_home_user_info(user_id): ......... {% show_home_user_info people.uid.text %} 2010 8 29
  31. 31. Template tag 2010 8 29
  32. 32. 24 2010 8 29
  33. 33. for,if,ifequal.... 2010 8 29
  34. 34. {% for o in some_list %} <tr class="{% cycle 'row1' 'row2' %}"> ... </tr> {% endfor %} 2010 8 29
  35. 35. Template filter 2010 8 29
  36. 36. 30+ 2010 8 29
  37. 37. {{ value|linebreaksbr }} 2010 8 29
  38. 38. {{ value|linenumbers }} 1. one 2. two 3. three 2010 8 29
  39. 39. {{ value|random }} [a,b,c,d]->b 2010 8 29
  40. 40. {{ value|title }} "my first post"->"My First Post" 2010 8 29
  41. 41. tag &filter 2010 8 29
  42. 42. @register.filter def join_list(arr): return ",".join(arr) 2010 8 29
  43. 43. , 2010 8 29
  44. 44. 2010 8 29
  45. 45. 页 http://docs.djangoproject.com/en/1.1/topics/pagination/ 2010 8 29
  46. 46. contact_list = Contacts.objects.all() paginator = Paginator(contact_list, 25) # Show 25 2010 8 29
  47. 47. from django.core.paginator import Paginator, InvalidPage, EmptyPage def listing(request): contact_list = Contacts.objects.all() paginator = Paginator(contact_list, 25) # Show 25 contacts per page # Make sure page request is an int. If not, deliver first page. try: page = int(request.GET.get('page', '1')) except ValueError: page = 1 # If page request (9999) is out of range, deliver last page of results. try: contacts = paginator.page(page) except (EmptyPage, InvalidPage): contacts = paginator.page(paginator.num_pages) return render_to_response('list.html', {"contacts": contacts}) 2010 8 29
  48. 48. {% for contact in contacts.object_list %} {# Each "contact" is a Contact model object. #} {{ contact.full_name|upper }}<br /> ... {% endfor %} <div class="pagination"> <span class="step-links"> {% if contacts.has_previous %} <a href="? page={{ contacts.previous_page_number }}">previous</a> {% endif %} <span class="current"> Page {{ contacts.number }} of {{ contacts.paginator.num_pages }}. </span> {% if contacts.has_next %} <a href="? page={{ contacts.next_page_number }}">next</a> {% endif %} </span> </div> 2010 8 29
  49. 49. Middleware 2010 8 29
  50. 50. OpenID 2010 8 29
  51. 51. Django Auth 2010 8 29
  52. 52. AUTHENTICATION_BACKENDS= ( 'django.contrib.auth.backends.RemoteUserBackend', ) Openid? LDAP? database? 2010 8 29
  53. 53. Cache 2010 8 29
  54. 54. CACHE_BACKEND='redis_cache.cache://127.0.0.1:6379' CACHE_BACKEND='memcached://127.0.0.1:6379' from django.core.cache import cache ..... songs=cache.get('songs') if not songs: songs=super(SongManager, self).all(*args, **kwargs) cache.set('songs', songs, 3600*24*365) ...... 2010 8 29
  55. 55. 统 2010 8 29
  56. 56. ./manage.py [xxx] 2010 8 29
  57. 57. 统 2010 8 29
  58. 58. settings.py 2010 8 29
  59. 59. i18n 2010 8 29
  60. 60. ETag,Last-Modified 2010 8 29
  61. 61. 2010 8 29
  62. 62. django debug toolbar 2010 8 29
  63. 63. 2010 8 29
  64. 64. 2010 8 29
  65. 65. django extensions http://github.com/django-extensions/django-extensions 2010 8 29
  66. 66. Django Admin 2010 8 29
  67. 67. 2010 8 29
  68. 68. 2010 8 29
  69. 69. 2010 8 29
  70. 70. 2010 8 29
  71. 71. Django • ..... • • Django 发 业 统 2010 8 29
  72. 72. Django • http://bitbucket.org/qingfeng/django_genericview_wiki/ • 4 • http://www.djangobook.com/ • The Definitive Guide to Django [1798896] • Pro Django [3086812] 2010 8 29
  73. 73. ---- 风 2010 8 29
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×