若有一个已经运行稳定的程序,那么可以将其打包,供其他项目安装使用。

假设django项目的目录结构如下:

mysite/
manage.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py
polls/
__init__.py
admin.py
migrations/
__init__.py
0001_initial.py
models.py
static/
polls/
images/
background.gif
style.css
templates/
polls/
detail.html
index.html
results.html
tests.py
urls.py
views.py
templates/
admin/
base_site.html

想要把polls打包出去,首先将polls文件夹拷贝到一个新的目录下,如django-polls;

创建文件django-polls/README.rst,其内容如下:

=====
Polls
===== Polls is a simple Django app to conduct Web-based polls. For each
question, visitors can choose between a fixed number of answers. Detailed documentation is in the "docs" directory. Quick start
----------- 1. Add "polls" to your INSTALLED_APPS setting like this:: INSTALLED_APPS = [
...
'polls',
] 2. Include the polls URLconf in your project urls.py like this:: url(r'^polls/', include('polls.urls')), 3. Run `python manage.py migrate` to create the polls models. 4. Start the development server and visit http://127.0.0.1:8000/admin/
to create a poll (you'll need the Admin app enabled). 5. Visit http://127.0.0.1:8000/polls/ to participate in the poll.

创建了license文件,django-polls/LICENSE;

创建django-polls/setup.py文件,内容如下:

import os
from setuptools import find_packages, setup with open(os.path.join(os.path.dirname(__file__), 'README.rst')) as readme:
README = readme.read() # allow setup.py to be run from any path
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir))) setup(
name='django-polls',
version='0.1',
packages=find_packages(),
include_package_data=True,
license='BSD License', # example license
description='A simple Django app to conduct Web-based polls.',
long_description=README,
url='https://www.example.com/',
author='Your Name',
author_email='yourname@example.com',
classifiers=[
'Environment :: Web Environment',
'Framework :: Django',
'Framework :: Django :: X.Y', # replace "X.Y" as appropriate
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License', # example license
'Operating System :: OS Independent',
'Programming Language :: Python',
# Replace these appropriately if you are stuck on Python 2.
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
],
)

创建django-polls/MANIFEST.in文件,内容如下:

include LICENSE
include README.rst
recursive-include polls/static *
recursive-include polls/templates *

在目录django-polls下执行打包命令:python setup.py sdist,将会在目录sdist下产生压缩文件 django-polls-0.1.tar.gz.

使用时:

安装: pip install --user django-polls/dist/django-polls-0.1.tar.gz

卸载: pip uninstall django-polls

最新文章

  1. JavaMail发送邮件的笔记及Demo
  2. 关于JSP页面字段属性设为disabled或者readonly所带来的问题总结
  3. angularjs-$interval使用
  4. 无序数组的中位数(set+deque)hdu5249
  5. c# Random Class usage
  6. ASP.NET CompareValidator 控件在VS2012中出错的问题
  7. 详细介绍如何使用kindEditor编辑器
  8. 关于Django模板渲染一个很重要的用途
  9. Struts2, jquery, select二级联动
  10. 开源一个上架 App Store 的相机 App
  11. Android 屏幕刷新机制
  12. SUSE10的虚拟机安装以及ORACLE 11g的安装
  13. bzoj1497 最小割
  14. The MathType Dll cannot be found 问题解决办法
  15. PHP eval函数
  16. c:url标签
  17. mysql8.0关闭log-bin功能
  18. Java中HashSet的解读
  19. windows上memecache添加多个端口命令
  20. 沉淀,再出发:web前端的一些认识

热门文章

  1. service-web
  2. php chr()函数 语法
  3. Hbuild X 打包 混合式app
  4. 转载:解决npm安装时出现run `npm audit fix` to fix them, or `npm audit` for details
  5. dubbo 漫谈一
  6. 从单片机到系统之--uboot启动arm linux
  7. 基于Diff机制的多个状态合并
  8. Redis初阶
  9. Centos7安装gearman和php扩展
  10. QT简介及下载