http://python.usyiyi.cn/translate/django_182/intro/reusable-apps.html
可重用很重要
你在教程 2中创建了mysite/templates ,在教程 3中创建了polls/templates。 现在你可能更加清晰为什么我们为项目和应用选择单独的模板目录:属于投票应用的部分全部在polls中。它使得该应用“自包含(self-contained)”且更加容易丢到一个新的项目中。
Python 打包的目前状态因为有多种工具而混乱不堪。对于本教程,我们打算使用来构建我们的包。它是推荐的打包工具(已经与distribute 分支合并)
打包你的应用
step 1
mkdir django-tasks
mv tasks django-tasks
$ cat django-tasks/MANIFEST.in include LICENSEinclude README.rstrecursive-include tasks/static *recursive-include tasks/templates *recursive-include docs *$mkdir django-tasks/doc$touch django-tasks/README.rst$$ cat django-tasks/setup.py #!/usr/bin/env python#-*- coding: utf-8 -*-__author__ = 'Ye Lin'__date__ = '17-2-10'import osfrom setuptools import setupwith open(os.path.join(os.path.dirname(__file__), 'README.rst')) as readme: README = readme.read()# allow setup.py to be run from any pathos.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))setup( name='django-tasks', version='0.1', packages=['tasks'], include_package_data=True, license='BSD License', # example license description='A simple Django app to conduct Web-based tasks.', long_description=README, url='http://www.example.com/', author='ZSR', author_email='lynn_0401@163.com', classifiers=[ 'Environment :: Web Environment', 'Framework :: Django', '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.2', 'Programming Language :: Python :: 3.3', 'Topic :: Internet :: WWW/HTTP', 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', ],)$$ python setup.py sdistrunning sdistrunning egg_infowriting django_tasks.egg-info/PKG-INFOwriting top-level names to django_tasks.egg-info/top_level.txtwriting dependency_links to django_tasks.egg-info/dependency_links.txtreading manifest file 'django_tasks.egg-info/SOURCES.txt'reading manifest template 'MANIFEST.in'warning: no files found matching 'LICENSE'warning: no files found matching '*' under directory 'docs'writing manifest file 'django_tasks.egg-info/SOURCES.txt'running checkcreating django-tasks-0.1creating django-tasks-0.1/django_tasks.egg-infocreating django-tasks-0.1/taskscreating django-tasks-0.1/tasks/staticcreating django-tasks-0.1/tasks/static/taskscreating django-tasks-0.1/tasks/templatescreating django-tasks-0.1/tasks/templates/taskscopying files to django-tasks-0.1...copying MANIFEST.in -> django-tasks-0.1copying README.rst -> django-tasks-0.1copying setup.py -> django-tasks-0.1copying django_tasks.egg-info/PKG-INFO -> django-tasks-0.1/django_tasks.egg-infocopying django_tasks.egg-info/SOURCES.txt -> django-tasks-0.1/django_tasks.egg-infocopying django_tasks.egg-info/dependency_links.txt -> django-tasks-0.1/django_tasks.egg-infocopying django_tasks.egg-info/top_level.txt -> django-tasks-0.1/django_tasks.egg-infocopying tasks/__init__.py -> django-tasks-0.1/taskscopying tasks/admin.py -> django-tasks-0.1/taskscopying tasks/apps.py -> django-tasks-0.1/taskscopying tasks/models.py -> django-tasks-0.1/taskscopying tasks/tests.py -> django-tasks-0.1/taskscopying tasks/urls.py -> django-tasks-0.1/taskscopying tasks/views.py -> django-tasks-0.1/taskscopying tasks/static/tasks/style.css -> django-tasks-0.1/tasks/static/taskscopying tasks/templates/tasks/detail.html -> django-tasks-0.1/tasks/templates/taskscopying tasks/templates/tasks/index.html -> django-tasks-0.1/tasks/templates/taskscopying tasks/templates/tasks/results.html -> django-tasks-0.1/tasks/templates/tasksWriting django-tasks-0.1/setup.cfgCreating tar archiveremoving 'django-tasks-0.1' (and everything under it)
使用自己的包
$pip install --user django-tasks/dist/django-tasks-0.1.tar.gz Unpacking ./django-tasks/dist/django-tasks-0.1.tar.gz Running setup.py (path:/tmp/pip-y8B6hl-build/setup.py) egg_info for package from file:///home/ly/PycharmProjects/ltest/django-tasks/dist/django-tasks-0.1.tar.gz warning: no files found matching 'LICENSE' warning: no files found matching '*' under directory 'docs' Requirement already satisfied (use --upgrade to upgrade): django-tasks==0.1 from file:///home/ly/PycharmProjects/ltest/django-tasks/dist/django-tasks-0.1.tar.gz in /home/ly/.local/lib/python2.7/site-packagesCleaning up...
pip uninstall django-polls