• Like
  • Save
Django
Upcoming SlideShare
Loading in...5
×
 

Django

on

  • 1,316 views

Django入门讲座

Django入门讲座

Statistics

Views

Total Views
1,316
Views on SlideShare
1,316
Embed Views
0

Actions

Likes
2
Downloads
17
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Django Django Presentation Transcript

    • 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,views 2010 8 29
    • • • 统 • 发 • 跃 • .... 2010 8 29
    • 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.assertEqual(people.uid.text,'qingfeng') purl = 'http://t.douban.com/icon/u1001560-12.jpg' self.assertEqual(people.link[2].href,purl) 2010 8 29
    • T+V 2010 8 29
    • Generic Views 2010 8 29
    • 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
    • views.py zero! 2010 8 29
    • Demo 2010 8 29
    • 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
    • views 过 ? 2010 8 29
    • inclusion_tag 2010 8 29
    • @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
    • 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' %}"> ... </tr> {% endfor %} 2010 8 29
    • Template filter 2010 8 29
    • 30+ 2010 8 29
    • {{ value|linebreaksbr }} 2010 8 29
    • {{ value|linenumbers }} 1. one 2. two 3. three 2010 8 29
    • {{ 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): 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
    • {% 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
    • Middleware 2010 8 29
    • OpenID 2010 8 29
    • Django Auth 2010 8 29
    • AUTHENTICATION_BACKENDS= ( 'django.contrib.auth.backends.RemoteUserBackend', ) Openid? LDAP? database? 2010 8 29
    • Cache 2010 8 29
    • 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
    • 统 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 • http://www.djangobook.com/ • The Definitive Guide to Django [1798896] • Pro Django [3086812] 2010 8 29
    • ---- 风 2010 8 29