SlideShare a Scribd company logo
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

PDF
解密解密
Tom Chen
 
PDF
We Buy Cheese in a Cheese Shop
Tzu-ping Chung
 
PPS
Xmas
Tom Chen
 
PDF
Pytables
gowell
 
PDF
Command line 初級寶典
Tom Chen
 
PDF
Live Performance Effects
Tom Chen
 
PDF
真蝦意外接到的Case
Tom Chen
 
PDF
Two scoops of Django - Deployment
flywindy
 
解密解密
Tom Chen
 
We Buy Cheese in a Cheese Shop
Tzu-ping Chung
 
Xmas
Tom Chen
 
Pytables
gowell
 
Command line 初級寶典
Tom Chen
 
Live Performance Effects
Tom Chen
 
真蝦意外接到的Case
Tom Chen
 
Two scoops of Django - Deployment
flywindy
 

Viewers also liked (19)

PDF
Elasticsearch intro output
Tom Chen
 
PPTX
Two scoops of django Introduction
flywindy
 
PDF
AngularJS Sharing
Tom Chen
 
PDF
Django step0
永昇 陳
 
PPTX
Gitlab
Tom Chen
 
PDF
Working with the django admin
flywindy
 
PPTX
Python, Development Environment for Windows
Kwangyoun Jung
 
PDF
Python Recipes for django girls seoul
Joeun Park
 
PDF
愛樂工程師
Tom Chen
 
PDF
라이트닝 토크 2015 파이콘
Jiho Lee
 
PDF
Django e il Rap Elia Contini
WEBdeBS
 
PDF
NoSql Day - Chiusura
WEBdeBS
 
PDF
Vim for Mere Mortals
Clayton Parker
 
PDF
Django - The Web framework for perfectionists with deadlines
Markus Zapke-Gründemann
 
PDF
2007 - 应用系统脆弱性概论
Na Lee
 
PDF
PyClab.__init__(self)
Tzu-ping Chung
 
PDF
Website optimization
Mindfire Solutions
 
PPTX
Super Advanced Python –act1
Ke Wei Louis
 
PDF
2 × 3 = 6
Tzu-ping Chung
 
Elasticsearch intro output
Tom Chen
 
Two scoops of django Introduction
flywindy
 
AngularJS Sharing
Tom Chen
 
Django step0
永昇 陳
 
Gitlab
Tom Chen
 
Working with the django admin
flywindy
 
Python, Development Environment for Windows
Kwangyoun Jung
 
Python Recipes for django girls seoul
Joeun Park
 
愛樂工程師
Tom Chen
 
라이트닝 토크 2015 파이콘
Jiho Lee
 
Django e il Rap Elia Contini
WEBdeBS
 
NoSql Day - Chiusura
WEBdeBS
 
Vim for Mere Mortals
Clayton Parker
 
Django - The Web framework for perfectionists with deadlines
Markus Zapke-Gründemann
 
2007 - 应用系统脆弱性概论
Na Lee
 
PyClab.__init__(self)
Tzu-ping Chung
 
Website optimization
Mindfire Solutions
 
Super Advanced Python –act1
Ke Wei Louis
 
2 × 3 = 6
Tzu-ping Chung
 
Ad

Similar to Django sharing (6)

PDF
Objc under the_hood_2013
Michael Pan
 
PDF
Homework2 play cards
Michael Pan
 
PDF
Autolayout
Kevin Shen
 
PDF
Note something
Michael Pan
 
PDF
SeaJS - 前端模块化开发探索与网站性能优化实践
lifesinger
 
PDF
旺铺前端设计和实现
hua qiu
 
Objc under the_hood_2013
Michael Pan
 
Homework2 play cards
Michael Pan
 
Autolayout
Kevin Shen
 
Note something
Michael Pan
 
SeaJS - 前端模块化开发探索与网站性能优化实践
lifesinger
 
旺铺前端设计和实现
hua qiu
 
Ad

Django sharing