1 了解python package索引
Python Package Index (PyPI)
pip search package_name
2 了解 Django package
尽量使用第三方package, 避免造轮子
3 使用
cookiecutter
创建pypi
或者是django package
# 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
函数包裹文字内容
- 使用
_
来表示 翻译函数
from django.utils.translation import ugettext as _
t = time.localtime()[6]
weekdays = [_('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'),
_('Friday'), _('Saturday'), _('Sunday')]
print(_(weekdays[t]))