Django其他相关概念

1 了解python package索引 Python Package Index (PyPI)

pypi.python.org/pypi

pip search package_name

2 了解 Django package

(djangopackages.org)

尽量使用第三方package, 避免造轮子

3 使用cookiecutter创建 pypi 或者是 django package

cookiecutter

# Only if you haven't installed cookiecutter yet
$ pip install cookiecutter
# Creating a Django Package from scratch
$ cookiecutter https://github.com/pydanny/cookiecutter-djangopackage.git
# Creating a Python Package from scratch
$ cookiecutter https://github.com/audreyr/cookiecutter-pypackage.git

4 使用 twine 上传代码到 pypi

$ pip install twine
$ python setup.py sdist
$ twine upload dist/*

For Python 2.7: Define Python Source Code Encodings 指定py2+的编码格式

#!/usr/bin/python
# -*- coding: utf-8 -*-

使用 django.utils.translation函数包裹文字内容

django.utils.translation

  • 使用 _ 来表示 翻译函数
from django.utils.translation import ugettext as _

t = time.localtime()[6]
weekdays = [_('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'),
_('Friday'), _('Saturday'), _('Sunday')]

print(_(weekdays[t]))

Buy me a 肥仔水!