当Django 的application开发完成之后,我们希望能将其作为模块分发出去供别人共享使用
安装好Django之后
1 | ## create project |
创建一个父目录
mkdir -pv /opt/django-todo
copy 刚才新增的 application todo
到 该目录下
cp -r todo /opt/django-todo/
一般开发完成application之后,在todo
下面会生成__pycache__
和 migrations
, 一般会保留migrations
作为应用的初始化; 或者删除不打包到Python package中,安装应用之后可以使用python manage.py makemigrations todo
和 python manage.py migrate todo
来初始化;
__pycache__
可以删除不做打包
新增README.MD 和 setup.py
README.MD 作为项目的详细说明,这里省略,详细可以参考:todo README
setup.py 是打包安装脚本,详细脚本如下:
1 | import os |
编译打包、安装、注册、上传
python setup.py sdist
python setup.py register
python setup.py upload
新增~/.pypirc
而不是 ~/.pypi
刚才报错Server response (410): Project pre-registration is no longer required or supported, so continue dire
就是配置文件命名成了 ~/.pypi
1 | [distutils] |
you can install via pip
pip install colinws-todo
or you can git clone this repository and use setup.py
git clone https://github.com/opscolin/Django-todo.git
cd Django-todo
python setup.py install
Add "todo"
to your INSTALLED_APPS
setting like this:
INSTALLED_APPS = [ ... 'todo',]
Include the todo URLconf
in your project urls.py
like this:
url(r'^todo/', include('todo.urls')),
Run below command to create todo models migrations.:
python manage.py makemigrations todo
Run below command to create todo real models.:
python manage.py migrate todo
Start the development server and visit http://127.0.0.1:8000/admin/ to create a todo (you’ll need the Admin app enabled).
Visit http://127.0.0.1:8000/todo/ to participate in the todo list.