SlideShare ist ein Scribd-Unternehmen logo
1 von 32
Django ,[object Object]
网络开发人员的开发流程 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Django History ,[object Object],[object Object],[object Object],[object Object],[object Object]
Django ,[object Object]
Django ,[object Object]
Django 的哲学 ,[object Object],[object Object],[object Object]
Quick Start ,[object Object]
Django 是把瑞士军刀 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Filter ,[object Object],[object Object]
toage @register.filter def toage( birthday): ‘’’ >>> toage( datetime(1982,3,23) ) 27 ‘’’ return (datetime.now()-birthday).days()/365
Simple Tag ,[object Object],[object Object]
current_time @register.simple_tag def current_time(format_string):  return datetime.now().strftime(format_string)
ORM 文章 图片 评论
Cache ,[object Object],[object Object],[object Object]
Auth ,[object Object],[object Object],[object Object],[object Object]
切换认证 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? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
我选择 Django 的原因 ,[object Object],[object Object],[object Object],[object Object]
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)
常见问题 ,[object Object],[object Object],[object Object],[object Object]
缺点 ,[object Object],[object Object],[object Object],[object Object]
django Dev ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
 
Thanks

Weitere ähnliche Inhalte

Ähnlich wie Django讲座

2009 Tw Oh Wretch Api
2009 Tw Oh Wretch Api2009 Tw Oh Wretch Api
2009 Tw Oh Wretch Api
JH Lee
 
TWOHD_Wretch API
TWOHD_Wretch APITWOHD_Wretch API
TWOHD_Wretch API
JH Lee
 
Windows Mobile Widget 開發
Windows Mobile Widget 開發Windows Mobile Widget 開發
Windows Mobile Widget 開發
Chui-Wen Chiu
 
Using google appengine_1027
Using google appengine_1027Using google appengine_1027
Using google appengine_1027
Wei Sun
 
2011/08/20跨平台行動應用程式使用者介面開發—以titanium mobile為例
2011/08/20跨平台行動應用程式使用者介面開發—以titanium mobile為例2011/08/20跨平台行動應用程式使用者介面開發—以titanium mobile為例
2011/08/20跨平台行動應用程式使用者介面開發—以titanium mobile為例
Justin Lee
 
Django development
Django developmentDjango development
Django development
loveyudu
 
Denver CMS Expo Creating CSS template
Denver CMS Expo Creating CSS templateDenver CMS Expo Creating CSS template
Denver CMS Expo Creating CSS template
compassdesign
 
由一个简单的程序谈起――之二
由一个简单的程序谈起――之二由一个简单的程序谈起――之二
由一个简单的程序谈起――之二
yiditushe
 

Ähnlich wie Django讲座 (20)

2009 Tw Oh Wretch Api
2009 Tw Oh Wretch Api2009 Tw Oh Wretch Api
2009 Tw Oh Wretch Api
 
Symfony簡介
Symfony簡介Symfony簡介
Symfony簡介
 
刘松 Cpo项目的前端实践分享
刘松 Cpo项目的前端实践分享刘松 Cpo项目的前端实践分享
刘松 Cpo项目的前端实践分享
 
漫談 Source Control Management
漫談 Source Control Management漫談 Source Control Management
漫談 Source Control Management
 
Mopcon2014 - 使用 Sinatra 結合 Ruby on Rails 輕鬆打造完整 Full Stack 網站加 API Service服務
Mopcon2014 - 使用 Sinatra 結合 Ruby on Rails 輕鬆打造完整 Full Stack 網站加 API Service服務Mopcon2014 - 使用 Sinatra 結合 Ruby on Rails 輕鬆打造完整 Full Stack 網站加 API Service服務
Mopcon2014 - 使用 Sinatra 結合 Ruby on Rails 輕鬆打造完整 Full Stack 網站加 API Service服務
 
TBAD F2E 2010 review
TBAD F2E 2010 reviewTBAD F2E 2010 review
TBAD F2E 2010 review
 
TWOHD_Wretch API
TWOHD_Wretch APITWOHD_Wretch API
TWOHD_Wretch API
 
Anroid development part.1
Anroid development part.1Anroid development part.1
Anroid development part.1
 
在雲端上啜飲爪哇
在雲端上啜飲爪哇在雲端上啜飲爪哇
在雲端上啜飲爪哇
 
Windows Mobile Widget 開發
Windows Mobile Widget 開發Windows Mobile Widget 開發
Windows Mobile Widget 開發
 
Using google appengine_1027
Using google appengine_1027Using google appengine_1027
Using google appengine_1027
 
2011/08/20跨平台行動應用程式使用者介面開發—以titanium mobile為例
2011/08/20跨平台行動應用程式使用者介面開發—以titanium mobile為例2011/08/20跨平台行動應用程式使用者介面開發—以titanium mobile為例
2011/08/20跨平台行動應用程式使用者介面開發—以titanium mobile為例
 
與 Sign in with Apple 的愛恨情仇 @ iPlayground2020
與 Sign in with Apple 的愛恨情仇 @ iPlayground2020與 Sign in with Apple 的愛恨情仇 @ iPlayground2020
與 Sign in with Apple 的愛恨情仇 @ iPlayground2020
 
Odoo Development
Odoo DevelopmentOdoo Development
Odoo Development
 
Django development
Django developmentDjango development
Django development
 
Denver CMS Expo Creating CSS template
Denver CMS Expo Creating CSS templateDenver CMS Expo Creating CSS template
Denver CMS Expo Creating CSS template
 
Creating CSS Template with Barrie North
Creating CSS Template with Barrie NorthCreating CSS Template with Barrie North
Creating CSS Template with Barrie North
 
用 Standalone Component 來寫 Angular 吧! - STUDY4.TW 2023 小聚 - 聊前端
用 Standalone Component 來寫 Angular 吧! - STUDY4.TW 2023 小聚 - 聊前端 用 Standalone Component 來寫 Angular 吧! - STUDY4.TW 2023 小聚 - 聊前端
用 Standalone Component 來寫 Angular 吧! - STUDY4.TW 2023 小聚 - 聊前端
 
Flutter實作概述 | GDSC NYCU
Flutter實作概述 | GDSC NYCUFlutter實作概述 | GDSC NYCU
Flutter實作概述 | GDSC NYCU
 
由一个简单的程序谈起――之二
由一个简单的程序谈起――之二由一个简单的程序谈起――之二
由一个简单的程序谈起――之二
 

Mehr von Qing Feng (9)

Code
CodeCode
Code
 
PyCon大会分享
PyCon大会分享PyCon大会分享
PyCon大会分享
 
Django
DjangoDjango
Django
 
Python交流
Python交流Python交流
Python交流
 
第5讲
第5讲第5讲
第5讲
 
第四讲
第四讲第四讲
第四讲
 
Tc&Tt
Tc&TtTc&Tt
Tc&Tt
 
第三讲
第三讲第三讲
第三讲
 
第二讲
第二讲第二讲
第二讲
 

Django讲座

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10. toage @register.filter def toage( birthday): ‘’’ >>> toage( datetime(1982,3,23) ) 27 ‘’’ return (datetime.now()-birthday).days()/365
  • 11.
  • 12. current_time @register.simple_tag def current_time(format_string): return datetime.now().strftime(format_string)
  • 14.
  • 15.
  • 16. 切换认证 AUTHENTICATION_BACKENDS=( 'sinard.ldapauth.LDAPBackend', #'django.contrib.auth.backends.ModelBackend', )
  • 17. Auth {% if user.is_authenticated %} <p>Welcome, {{ user.username }}. Thanks for logging in.</p>{% else %} <p>Welcome, new user. Please log in.</p>{% endif %}
  • 18. 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 %}
  • 19. 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;) # ...
  • 20. @login_required from django.contrib.auth.decorators import login_required@login_requireddef my_view(request): # ...
  • 21. 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>
  • 22. 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'
  • 23. 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'}
  • 24.
  • 25.
  • 27. admin.py from django.contrib import adminfrom myproject.myapp.models import Authoradmin.site.register(Author)
  • 28.
  • 29.
  • 30.
  • 31.