接上回 最终得到这样的目录
mysite/manage.pymysite/__init__.pysettings.pyurls.pyasgi.pywsgi.pypolls/__init__.pyadmin.pyapps.pymigrations/__init__.py0001_initial.pymodels.pystatic/polls/images/background.gifstyle.csstemplates/polls/detail.htmlindex.htmlresults.htmltests.pyurls.pyviews.pytemplates/admin/base_site.html
安装打包工具
# pip install setuptools
组织子应用 并写点介绍文件
-
任意外面的目录 起个名字并建文件夹 django-polls
-
复制 polls 到django-polls
-
写 README.rst 文件
===== Polls =====Polls is a 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::path('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 文件
-
写 pyproject.toml setup.cfg setup.py 文件 介绍如何构建安装 app
pyproject.toml
[build-system] requires = ['setuptools>=40.8.0', 'wheel'] build-backend = 'setuptools.build_meta:__legacy__'
setup.py
from setuptools import setupsetup()
setup.cfg
[metadata] name = django-polls version = 0.1 description = A Django app to conduct web-based polls. long_description = file: README.rst url = https://www.example.com/ author = Your Name author_email = yourname@example.com license = BSD-3-Clause # Example license classifiers =Environment :: Web EnvironmentFramework :: DjangoFramework :: Django :: X.Y # Replace "X.Y" as appropriateIntended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Internet :: WWW/HTTPTopic :: Internet :: WWW/HTTP :: Dynamic Content[options] include_package_data = true packages = find: python_requires = >=3.8 install_requires =Django >= X.Y # Replace "X.Y" as appropriate
包含其他文件
默认情况下,包中仅包含 Python 模块和包。 要包含其他文件,我们需要创建一个 MANIFEST.in 文件。 上一步中提到的 setuptools 文档更详细地讨论了这个文件。 要包含模板、README.rst 和我们的 LICENSE 文件,创建一个文件 django-polls/MANIFEST.in ,其内容如下:
include LICENSE
include README.rst
recursive-include polls/static *
recursive-include polls/templates *
包含详细文档(可选)
- 创建一个空目录 django-polls/docs
- 补充一行代码 django-polls/MANIFEST.in
recursive-include docs *
构建
D:\此电脑下分类\桌面\django-polls>
D:\此电脑下分类\桌面\django-polls>python setup.py sdist
running sdist
running egg_info
creating django_polls.egg-info
writing django_polls.egg-info\PKG-INFO
writing dependency_links to django_polls.egg-info\dependency_links.txt
........