Your SlideShare is downloading. ×
0
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Django
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Django

1,085

Published on

Django入门讲座

Django入门讲座

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

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

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Django qingfeng@douban.com 2010 8 29
  • 2. Django? 2010 8 29
  • 3. ,Web 发 动 3 2010 8 29
  • 4. 4 2010 8 29
  • 5. 过 Django web 东 5 2010 8 29
  • 6. 达 这 Django Web 发 业 6 2010 8 29
  • 7. “ ” 7 2010 8 29
  • 8. 时 Django framework 发 8 2010 8 29
  • 9. Django &历 • M-T-V • • DRY • Unix 艺术 2010 8 29
  • 10. Django • startproject [project_name] • startapp [app_name] • write urls,views 2010 8 29
  • 11. • • 统 • 发 • 跃 • .... 2010 8 29
  • 12. Django 录 2010 8 29
  • 13. M 2010 8 29
  • 14. Lyrics.objects.get_user_lyrics(uid) lyrics.get_creator() 2010 8 29
  • 15. 页 2010 8 29
  • 16. Lyrics.object.all() 发 SQL , 历 发 询 2010 8 29
  • 17. l=Lyrics.object.get(id=10) song = l.song -> [发 SQL] join SQL 2010 8 29
  • 18. 2010 8 29
  • 19. luzong/ 2010 8 29
  • 20. 单 2010 8 29
  • 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. T+V 2010 8 29
  • 23. Generic Views 2010 8 29
  • 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. views.py zero! 2010 8 29
  • 26. Demo 2010 8 29
  • 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. views 过 ? 2010 8 29
  • 29. inclusion_tag 2010 8 29
  • 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. Template tag 2010 8 29
  • 32. 24 2010 8 29
  • 33. for,if,ifequal.... 2010 8 29
  • 34. {% for o in some_list %} <tr class="{% cycle 'row1' 'row2' %}"> ... </tr> {% endfor %} 2010 8 29
  • 35. Template filter 2010 8 29
  • 36. 30+ 2010 8 29
  • 37. {{ value|linebreaksbr }} 2010 8 29
  • 38. {{ value|linenumbers }} 1. one 2. two 3. three 2010 8 29
  • 39. {{ value|random }} [a,b,c,d]->b 2010 8 29
  • 40. {{ value|title }} "my first post"->"My First Post" 2010 8 29
  • 41. tag &filter 2010 8 29
  • 42. @register.filter def join_list(arr): return ",".join(arr) 2010 8 29
  • 43. , 2010 8 29
  • 44. 2010 8 29
  • 45. 页 http://docs.djangoproject.com/en/1.1/topics/pagination/ 2010 8 29
  • 46. contact_list = Contacts.objects.all() paginator = Paginator(contact_list, 25) # Show 25 2010 8 29
  • 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. {% 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. Middleware 2010 8 29
  • 50. OpenID 2010 8 29
  • 51. Django Auth 2010 8 29
  • 52. AUTHENTICATION_BACKENDS= ( 'django.contrib.auth.backends.RemoteUserBackend', ) Openid? LDAP? database? 2010 8 29
  • 53. Cache 2010 8 29
  • 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. 统 2010 8 29
  • 56. ./manage.py [xxx] 2010 8 29
  • 57. 统 2010 8 29
  • 58. settings.py 2010 8 29
  • 59. i18n 2010 8 29
  • 60. ETag,Last-Modified 2010 8 29
  • 61. 2010 8 29
  • 62. django debug toolbar 2010 8 29
  • 63. 2010 8 29
  • 64. 2010 8 29
  • 65. django extensions http://github.com/django-extensions/django-extensions 2010 8 29
  • 66. Django Admin 2010 8 29
  • 67. 2010 8 29
  • 68. 2010 8 29
  • 69. 2010 8 29
  • 70. 2010 8 29
  • 71. Django • ..... • • Django 发 业 统 2010 8 29
  • 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. ---- 风 2010 8 29

×