您的位置:首页 > 移动开发

django-8,写高复用的app

2018-01-24 00:00 169 查看
摘要: 讲应用打包,开源,使用pip安装使用

就像再setting里面调用app和url里面使用include方便,我们可以做更多

讲polls 复制到新建文件夹django-polls(尽量避免重复)

Create a file
django-polls/README.rst
with the following contents:

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::

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.

Create a
django-polls/LICENSE
fil

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-fuan',
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 :: 2.0,  # replace "X.Y" as appropriate
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',  # example license
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
],
)

create a
MANIFEST.in
file.

django-polls/MANIFEST.in

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


Note that the
docs
directory won’t be included in your package unless you add some files to it. Many Django apps also provide their documentation online through sites like readthedocs.org.

recursive-include docs *


Try building your package with
python setup.py sdist
(run from inside
django-polls
). This creates a directory called
dist
and builds your new package,
django-polls-fuhan-0.1.tar.gz
.

使用

pip install --user django-polls/dist/django-polls-fuhan-0.1.tar.gz

pip uninstall django-polls

开源并上传

注册账号
https://pypi.python.org/pypi?%3Aaction=register_form
pip install twine

twine upload dist/*

上传成功之后便可以用pip安装使用了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: