• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Django讲座
 

Django讲座

on

  • 3,201 views

部门Django讲座用的讲稿

部门Django讲座用的讲稿

Statistics

Views

Total Views
3,201
Views on SlideShare
3,192
Embed Views
9

Actions

Likes
14
Downloads
70
Comments
2

1 Embed 9

http://www.slideshare.net 9

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

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

12 of 2 previous next

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • REFERENCING SLIDESHARE GROUP 'KINGDOM OF BELGIUM' (Django Reinhardt)
    This group 'KINGDOM OF BELGIUM' aims to gather all people worldwide who love the Belgium, and their presentations. It is dedicated to ALL aspects of Belgium, without exception. Its history, its geography, its culture, its politic, its economy,tourism, literature, its varieties, Song, art, cinema, theater, etc.. In short all Sound slideshows or not (documents, simple slideshow, slidecast, youtube, video)... I welcome you! Join us! Thank you in advance for your support.

    http://www.slideshare.net/group/kingdom-of-belgium
    Are you sure you want to
    Your message goes here
    Processing…
  • 用 Web2py 来讲吧,这是专门为教学而开发的一个企业级框架
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Django讲座 Django讲座 Presentation Transcript

    • Django
      • [email_address]
    • 网络开发人员的开发流程
      • 从头开始编写网络应用程序。
      • 从头编写另一个网络应用程序。
      • 从第一步中总结(找出其中通用的代码),并运用在第二步中。
      • 重构代码使得能在第 2 个程序中使用第 1 个程序中的通用代码。
      • 重复 2-4 步骤若干次。
      • 意识到你发明了一个框架。
    • Django History
      • 2003 开始
      • LJWorld.com Lawrence.com KUsports.com
      • Adrian Holovaty & Simon Willison
      • 2005.7
      • 爵士乐吉他演奏家 Django Reinhardt
    • Django
      • Django 最可爱的地方 , 因为 Django 诞生于一个新闻环境 , 她提供了很多的功能 , 特别是她的管理接口 , 特别适合提供内容的网站
    • Django
      • 不要看到这就感到沮丧,尽管 Django 擅长于动态内容管理系统, 但并不表示 Django 主要的目的就是用来创建动态内容的网站。 某些方面 特别高效 与 其他方面 不高效 是有区别的
    • Django 的哲学
      • 模板要保持简单
      • 不能替代 SQL 的 ORM
      • 鼓励测试
    • Quick Start
      • 演示
    • Django 是把瑞士军刀
      • Filter & Tag
      • ORM[ 常见关系模型 and 数据库 ]
      • Cache
      • Auth
      • Upload file
      • Form
      • .......
    • Filter
      • <td>{{ user.birthday|toage }}</td>
      • <td>{{ user.username|capfirst }}</td>
    • toage @register.filter def toage( birthday): ‘’’ >>> toage( datetime(1982,3,23) ) 27 ‘’’ return (datetime.now()-birthday).days()/365
    • Simple Tag
      • {%if name%} {{name}} {%endif%}
      • {% current_time &quot;%Y-%m-%d %I:%M %p&quot; %}
    • current_time @register.simple_tag def current_time(format_string): return datetime.now().strftime(format_string)
    • ORM 文章 图片 评论
    • Cache
      • CACHE_BACKEND = 'memcached://127.0.0.1:11211/'
      • >>> cache.set('my_key', 'hello, world!', 30)
      • >>> cache.get('my_key')
    • Auth
      • 切换不同的认证系统
      • 用户 , 组 , 权限的管理
      • 在模板中使用认证
      • 在代码中使用认证
    • 切换认证 AUTHENTICATION_BACKENDS=( 'sinard.ldapauth.LDAPBackend', #'django.contrib.auth.backends.ModelBackend', )
    • Auth {% if user.is_authenticated %} <p>Welcome, {{ user.username }}. Thanks for logging in.</p>{% else %} <p>Welcome, new user. Please log in.</p>{% endif %}
    • Permissions {% if perms.foo %} <p>You have permission to do something in the foo app.</p> {% if perms.foo.can_vote %} <p>You can vote!</p> {% endif %} {% if perms.foo.can_drive %} <p>You can drive!</p> {% endif %}{% else %} <p>You don't have permission to do anything in the foo app.</p>{% endif %}
    • in Views def my_view(request): if not (request.user.is_authenticated() and request.user.has_perm('polls.can_vote')): return HttpResponse(&quot;You can't vote in this poll.&quot;) # ...
    • @login_required from django.contrib.auth.decorators import login_required@login_requireddef my_view(request): # ...
    • Form >>> class CommentForm(forms.Form):... name = forms.CharField(initial='class')... url = forms.URLField()... comment = forms.CharField()>>> f = CommentForm(initial={'name': 'instance'}, auto_id=False)>>> print f<tr><th>Name:</th><td><input type=&quot;text&quot; name=&quot;name&quot; value=&quot;instance&quot; /></td></tr><tr><th>Url:</th><td><input type=&quot;text&quot; name=&quot;url&quot; /></td></tr><tr><th>Comment:</th><td><input type=&quot;text&quot; name=&quot;comment&quot; /></td></tr>
    • cleaned_data >>> data = {'subject': '',... 'message': 'Hi there',... 'sender': 'invalid e-mail address',... 'cc_myself': True}>>> f = ContactForm(data)>>> f.is_valid()False>>> f.cleaned_data...AttributeError: 'ContactForm' object has no attribute 'cleaned_data'
    • cleaned_data >>> data = {'subject': 'hello',... 'message': 'Hi there',... 'sender': ' [email_address] ',... 'cc_myself': True,... 'extra_field_1': 'foo',... 'extra_field_2': 'bar',... 'extra_field_3': 'baz'}>>> f = ContactForm(data)>>> f.is_valid()True>>> f.cleaned_data # Doesn't contain extra_field_1, etc.{'cc_myself': True, 'message': u'Hi there', 'sender': u' [email_address] ', 'subject': u 'hello'}
    • Why Django?
      • django
      • tg
      • pylons
      • uliweb
      • ror
      • ........
    • 我选择 Django 的原因
      • 质朴
      • 方便开发
      • Web 是一个由简单到复杂的过程
      • 用一个框架可以减少重复建设时间
    • Django Admin http://docs.djangoproject.com/en/dev/ref/contrib/admin/# ref-contrib-admin
    • admin.py from django.contrib import adminfrom myproject.myapp.models import Authoradmin.site.register(Author)
    • 常见问题
      • ORM 不支持的 SQL 怎么办
      • Django 如何连接 mysql
      • 听说 django 模板引擎效率很低
      • 我应该基于 Django Admin 做开发吗
    • 缺点
      • 不够友好的 URL 规则
      • 不支持多数据库操作
      • 文档 0.96 1.0 1.1 Dev.....
      • 中文资料
    • django Dev
      • 加入到 Django 的开发中来
      • http://code.djangoproject.com/newticket
      • svn diff
      • .diff file
      • 最好带上测试代码
      • Code Style: http://is.gd/4DIAE
    •  
    • Thanks