SlideShare a Scribd company logo
1 of 15
Download to read offline
DJANGO
a little sharing
陳炯廷 @ House123
ctchen@gmail.com
13年7月9⽇日星期⼆二
JINJA2
http://jinja.pocoo.org/docs/
13年7月9⽇日星期⼆二
{%- %}
就不會出現空⽩白⾏行 (潔癖 orz)
13年7月9⽇日星期⼆二
{{ movie.is_showing() }}
13年7月9⽇日星期⼆二
settings.py
from	
  unipath	
  import	
  Path
PROJECT_DIR	
  =	
  Path(__file__).ancestor(3)
MEDIA_ROOT	
  =	
  PROJECT_DIR.child(‘media’)
STATIC_ROOT	
  =	
  PROJECT_DIR.child(‘static_collected’)
13年7月9⽇日星期⼆二
settings.py
keys	
  =	
  [
	
  	
  	
  	
  'FACEBOOK_APP_ID',
	
  	
  	
  	
  'FACEBOOK_API_SECRET',
	
  	
  	
  	
  'AWS_ACCESS_KEY_ID',
	
  	
  	
  	
  'AWS_SECRET_ACCESS_KEY',
	
  	
  	
  	
  'MANDRILL_API_KEY',
	
  	
  	
  	
  'ANALYTICS_CODE',
	
  	
  	
  	
  'BROKER_URL',
]
for	
  key	
  in	
  keys:
	
  	
  	
  	
  if	
  key	
  not	
  in	
  locals():
	
  	
  	
  	
  	
  	
  	
  	
  if	
  key	
  not	
  in	
  os.environ:
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  print	
  '%s	
  not	
  found	
  in	
  ENVIRONMENT'	
  %	
  key
	
  	
  	
  	
  	
  	
  	
  	
  else:
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  vars()[key]	
  =	
  os.environ[key]
13年7月9⽇日星期⼆二
virtualenvwrapper
$	
  workon	
  moviefun
(moviefun)$	
  
13年7月9⽇日星期⼆二
virtualenvwrapper
[~/envs/moviefun/bin/postactivate]
export	
  AWS_ACCESS_KEY_ID=blablabla
export	
  AWS_SECRET_ACCESS_KEY=blablabla
13年7月9⽇日星期⼆二
moviefun.tw
moviefun.com.hk
def	
  nav(request):
	
  	
  	
  	
  if	
  request.path[0]	
  ==	
  '/':
	
  	
  	
  	
  	
  	
  	
  	
  path	
  =	
  request.path[1:]
	
  	
  	
  	
  else:
	
  	
  	
  	
  	
  	
  	
  	
  path	
  =	
  request.path
	
  	
  	
  	
  splited	
  =	
  path.split('/')
	
  	
  	
  	
  out	
  =	
  {}
	
  	
  	
  	
  for	
  index,	
  part	
  in	
  enumerate(splited):
	
  	
  	
  	
  	
  	
  	
  	
  out['nav_%d'	
  %	
  index]	
  =	
  part
	
  	
  	
  	
  domain_name	
  =	
  request.META.get('HTTP_HOST').split(':')[0]
	
  	
  	
  	
  out['query_city']	
  =	
  'taipei'
	
  	
  	
  	
  if	
  domain_name.split('.')[-­‐1]	
  ==	
  'hk':
	
  	
  	
  	
  	
  	
  	
  	
  out['query_city']	
  =	
  'hongkong'
	
  	
  	
  	
  return	
  out
context_processors.py
13年7月9⽇日星期⼆二
def	
  analytics(request):
	
  	
  	
  	
  if	
  hasattr(settings,	
  'ANALYTICS_ACCOUNT'):
	
  	
  	
  	
  	
  	
  	
  	
  return	
  {'ANALYTICS_ACCOUNT':	
  settings.ANALYTICS_ACCOUNT}
	
  	
  	
  	
  return	
  {}
context_processors.py
13年7月9⽇日星期⼆二
dir layout
moviefun/
	
  	
  django/
	
  	
  	
  	
  moviefun/
	
  	
  	
  	
  	
  	
  settings/
	
  	
  	
  	
  ticket/
	
  	
  	
  	
  templates/
	
  	
  	
  	
  static/
	
  	
  	
  	
  	
  	
  3rd_party/
	
  	
  	
  	
  	
  	
  	
  	
  jQuery/
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  1.10.2/
	
  	
  	
  	
  	
  	
  css/
	
  	
  	
  	
  	
  	
  js/
	
  	
  	
  	
  	
  	
  images/
	
  	
  	
  	
  media/
	
  	
  	
  	
  static_collected/
13年7月9⽇日星期⼆二
moviefun/
	
  	
  django/
	
  	
  	
  	
  moviefun/
	
  	
  	
  	
  	
  	
  settings/
	
  	
  	
  	
  ticket/
	
  	
  	
  	
  templates/
	
  	
  	
  	
  static/
	
  	
  	
  	
  	
  	
  3rd_party/
	
  	
  	
  	
  	
  	
  	
  	
  jQuery/
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  1.10.2/
	
  	
  	
  	
  	
  	
  css/
	
  	
  	
  	
  	
  	
  js/
	
  	
  	
  	
  	
  	
  images/
	
  	
  	
  	
  media/
	
  	
  	
  	
  static_collected/
dir layout
heroku
要在第⼀一層
13年7月9⽇日星期⼆二
BULK IMPORT
Microsoft Excel
xlrd
xlwd
13年7月9⽇日星期⼆二
CELERY / GEVENT
13年7月9⽇日星期⼆二
DJANGO-COMPRESSOR
DJANGO-PIPELINE
13年7月9⽇日星期⼆二

More Related Content

Viewers also liked

Elasticsearch intro output
Elasticsearch intro outputElasticsearch intro output
Elasticsearch intro outputTom Chen
 
Two scoops of django Introduction
Two scoops of django IntroductionTwo scoops of django Introduction
Two scoops of django Introductionflywindy
 
AngularJS Sharing
AngularJS SharingAngularJS Sharing
AngularJS SharingTom Chen
 
Working with the django admin
Working with the django admin Working with the django admin
Working with the django admin flywindy
 
Python, Development Environment for Windows
Python, Development Environment for WindowsPython, Development Environment for Windows
Python, Development Environment for WindowsKwangyoun Jung
 
Python Recipes for django girls seoul
Python Recipes for django girls seoulPython Recipes for django girls seoul
Python Recipes for django girls seoulJoeun Park
 
愛樂工程師
愛樂工程師愛樂工程師
愛樂工程師Tom Chen
 
라이트닝 토크 2015 파이콘
라이트닝 토크 2015 파이콘라이트닝 토크 2015 파이콘
라이트닝 토크 2015 파이콘Jiho Lee
 
Django e il Rap Elia Contini
Django e il Rap Elia ContiniDjango e il Rap Elia Contini
Django e il Rap Elia ContiniWEBdeBS
 
NoSql Day - Chiusura
NoSql Day - ChiusuraNoSql Day - Chiusura
NoSql Day - ChiusuraWEBdeBS
 
Django - The Web framework for perfectionists with deadlines
Django - The Web framework for perfectionists with deadlinesDjango - The Web framework for perfectionists with deadlines
Django - The Web framework for perfectionists with deadlinesMarkus Zapke-Gründemann
 
2007 - 应用系统脆弱性概论
2007 - 应用系统脆弱性概论 2007 - 应用系统脆弱性概论
2007 - 应用系统脆弱性概论 Na Lee
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1Ke Wei Louis
 

Viewers also liked (19)

Elasticsearch intro output
Elasticsearch intro outputElasticsearch intro output
Elasticsearch intro output
 
Two scoops of django Introduction
Two scoops of django IntroductionTwo scoops of django Introduction
Two scoops of django Introduction
 
AngularJS Sharing
AngularJS SharingAngularJS Sharing
AngularJS Sharing
 
Django step0
Django step0Django step0
Django step0
 
Gitlab
GitlabGitlab
Gitlab
 
Working with the django admin
Working with the django admin Working with the django admin
Working with the django admin
 
Python, Development Environment for Windows
Python, Development Environment for WindowsPython, Development Environment for Windows
Python, Development Environment for Windows
 
Python Recipes for django girls seoul
Python Recipes for django girls seoulPython Recipes for django girls seoul
Python Recipes for django girls seoul
 
愛樂工程師
愛樂工程師愛樂工程師
愛樂工程師
 
라이트닝 토크 2015 파이콘
라이트닝 토크 2015 파이콘라이트닝 토크 2015 파이콘
라이트닝 토크 2015 파이콘
 
Django e il Rap Elia Contini
Django e il Rap Elia ContiniDjango e il Rap Elia Contini
Django e il Rap Elia Contini
 
NoSql Day - Chiusura
NoSql Day - ChiusuraNoSql Day - Chiusura
NoSql Day - Chiusura
 
Vim for Mere Mortals
Vim for Mere MortalsVim for Mere Mortals
Vim for Mere Mortals
 
Django - The Web framework for perfectionists with deadlines
Django - The Web framework for perfectionists with deadlinesDjango - The Web framework for perfectionists with deadlines
Django - The Web framework for perfectionists with deadlines
 
2007 - 应用系统脆弱性概论
2007 - 应用系统脆弱性概论 2007 - 应用系统脆弱性概论
2007 - 应用系统脆弱性概论
 
PyClab.__init__(self)
PyClab.__init__(self)PyClab.__init__(self)
PyClab.__init__(self)
 
Website optimization
Website optimizationWebsite optimization
Website optimization
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1
 
2 × 3 = 6
2 × 3 = 62 × 3 = 6
2 × 3 = 6
 

Similar to Django sharing

Objc under the_hood_2013
Objc under the_hood_2013Objc under the_hood_2013
Objc under the_hood_2013Michael Pan
 
Homework2 play cards
Homework2 play cardsHomework2 play cards
Homework2 play cardsMichael Pan
 
SeaJS - 前端模块化开发探索与网站性能优化实践
SeaJS - 前端模块化开发探索与网站性能优化实践SeaJS - 前端模块化开发探索与网站性能优化实践
SeaJS - 前端模块化开发探索与网站性能优化实践lifesinger
 
旺铺前端设计和实现
旺铺前端设计和实现旺铺前端设计和实现
旺铺前端设计和实现hua qiu
 

Similar to Django sharing (6)

Objc under the_hood_2013
Objc under the_hood_2013Objc under the_hood_2013
Objc under the_hood_2013
 
Homework2 play cards
Homework2 play cardsHomework2 play cards
Homework2 play cards
 
Autolayout
AutolayoutAutolayout
Autolayout
 
Note something
Note somethingNote something
Note something
 
SeaJS - 前端模块化开发探索与网站性能优化实践
SeaJS - 前端模块化开发探索与网站性能优化实践SeaJS - 前端模块化开发探索与网站性能优化实践
SeaJS - 前端模块化开发探索与网站性能优化实践
 
旺铺前端设计和实现
旺铺前端设计和实现旺铺前端设计和实现
旺铺前端设计和实现
 

Django sharing