Django项目打包
这是目前开发完成的project目录树。我们要打包其中的polls app。
(v_python3.6) thinkt@linux-pw37:~/PycharmProjects/mysite> tree
.
├── db.sqlite3
├── mysite
│ ├── __init__.py
│ ├── __pycache__
│ │ ├── __init__.cpython-36.pyc
│ │ ├── settings.cpython-36.pyc
│ │ ├── urls.cpython-36.pyc
│ │ └── wsgi.cpython-36.pyc
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── polls
│ ├── admin.py
│ ├── apps.py
│ ├── __init__.py
│ ├── migrations
│ │ ├── 0001_initial.py
│ │ ├── 0002_auto_20170401_1758.py
│ │ ├── __init__.py
│ │ └── __pycache__
│ │ ├── 0001_initial.cpython-36.pyc
│ │ ├── 0002_auto_20170401_1758.cpython-36.pyc
│ │ └── __init__.cpython-36.pyc
│ ├── models.py
│ ├── __pycache__
│ │ ├── admin.cpython-36.pyc
│ │ ├── apps.cpython-36.pyc
│ │ ├── __init__.cpython-36.pyc
│ │ ├── models.cpython-36.pyc
│ │ ├── tests.cpython-36.pyc
│ │ ├── urls.cpython-36.pyc
│ │ └── views.cpython-36.pyc
│ ├── static
│ │ └── polls
│ │ ├── images
│ │ │ └── background.jpg
│ │ └── style.css
│ ├── templates
│ │ └── polls
│ │ ├── detail.html
│ │ ├── index.html
│ │ └── results.html
│ ├── tests.py
│ ├── urls.py
│ └── views.py
└── templates
└── admin
├── base_site.html
└── index.html
复制一份添加前辍头django,让人容易识别这是一个django项目。
(v_python3.6) thinkt@linux-pw37:~/PycharmProjects/mysite> cp polls django-polls -rfv
创建说明文件,方便其它人阅读。
(v_python3.6) thinkt@linux-pw37:~/PycharmProjects/mysite> vim 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.
创建setup.py脚本,提供详细的关于build,使用等方法。
(v_python3.6) thinkt@linux-pw37:~/PycharmProjects/mysite/django-polls> vim setup.py
(v_python3.6) thinkt@linux-pw37:~/PycharmProjects/mysite/django-polls> cat 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',
],
)
创建附加文件说明。
v_python3.6) thinkt@linux-pw37:~/PycharmProjects/mysite/django-polls> vim MANIFEST.in
(v_python3.6) thinkt@linux-pw37:~/PycharmProjects/mysite/django-polls> cat MANIFEST.in
include LICENSE
include README.rst
recursive-include polls/static *
recursive-include polls/templates *
recursive-include docs *
附加文件有有个docs目录,创建docs目录,如果有文档等放置在其中。
(v_python3.6) thinkt@linux-pw37:~/PycharmProjects/mysite/django-polls> mkdir docs
开始打包。
(v_python3.6) thinkt@linux-pw37:~/PycharmProjects/mysite/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
writing top-level names to django_polls.egg-info/top_level.txt
writing manifest file 'django_polls.egg-info/SOURCES.txt'
reading manifest file 'django_polls.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching 'LICENSE'
warning: no files found matching '*' under directory 'polls/static'
warning: no files found matching '*' under directory 'polls/templates'
warning: no files found matching '*' under directory 'docs'
writing manifest file 'django_polls.egg-info/SOURCES.txt'
running check
creating django-polls-0.1
creating django-polls-0.1/django_polls.egg-info
creating django-polls-0.1/migrations
copying files to django-polls-0.1...
copying MANIFEST.in -> django-polls-0.1
copying README.rst -> django-polls-0.1
copying setup.py -> django-polls-0.1
copying django_polls.egg-info/PKG-INFO -> django-polls-0.1/django_polls.egg-info
copying django_polls.egg-info/SOURCES.txt -> django-polls-0.1/django_polls.egg-info
copying django_polls.egg-info/dependency_links.txt -> django-polls-0.1/django_polls.egg-info
copying django_polls.egg-info/top_level.txt -> django-polls-0.1/django_polls.egg-info
copying migrations/0001_initial.py -> django-polls-0.1/migrations
copying migrations/0002_auto_20170401_1758.py -> django-polls-0.1/migrations
copying migrations/__init__.py -> django-polls-0.1/migrations
Writing django-polls-0.1/setup.cfg
creating dist
Creating tar archive
removing 'django-polls-0.1' (and everything under it)
在dist目录下存放了打包好的文件。
(v_python3.6) thinkt@linux-pw37:~/PycharmProjects/mysite/django-polls/dist> ll
总用量 4
-rw-r--r-- 1 thinkt users 2349 4月 18 15:08 django-polls-0.1.tar.gz
使用pip安装本地打包。
pip install --user django-polls/dist/django-polls-0.1.tar.gz
使用pip的uninstall删除
pip uninstall django-polls
参考:https://docs.djangoproject.com/en/1.10/intro/reusable-apps/
这是目前开发完成的project目录树。我们要打包其中的polls app。
(v_python3.6) thinkt@linux-pw37:~/PycharmProjects/mysite> tree
.
├── db.sqlite3
├── mysite
│ ├── __init__.py
│ ├── __pycache__
│ │ ├── __init__.cpython-36.pyc
│ │ ├── settings.cpython-36.pyc
│ │ ├── urls.cpython-36.pyc
│ │ └── wsgi.cpython-36.pyc
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── polls
│ ├── admin.py
│ ├── apps.py
│ ├── __init__.py
│ ├── migrations
│ │ ├── 0001_initial.py
│ │ ├── 0002_auto_20170401_1758.py
│ │ ├── __init__.py
│ │ └── __pycache__
│ │ ├── 0001_initial.cpython-36.pyc
│ │ ├── 0002_auto_20170401_1758.cpython-36.pyc
│ │ └── __init__.cpython-36.pyc
│ ├── models.py
│ ├── __pycache__
│ │ ├── admin.cpython-36.pyc
│ │ ├── apps.cpython-36.pyc
│ │ ├── __init__.cpython-36.pyc
│ │ ├── models.cpython-36.pyc
│ │ ├── tests.cpython-36.pyc
│ │ ├── urls.cpython-36.pyc
│ │ └── views.cpython-36.pyc
│ ├── static
│ │ └── polls
│ │ ├── images
│ │ │ └── background.jpg
│ │ └── style.css
│ ├── templates
│ │ └── polls
│ │ ├── detail.html
│ │ ├── index.html
│ │ └── results.html
│ ├── tests.py
│ ├── urls.py
│ └── views.py
└── templates
└── admin
├── base_site.html
└── index.html
复制一份添加前辍头django,让人容易识别这是一个django项目。
(v_python3.6) thinkt@linux-pw37:~/PycharmProjects/mysite> cp polls django-polls -rfv
创建说明文件,方便其它人阅读。
(v_python3.6) thinkt@linux-pw37:~/PycharmProjects/mysite> vim 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.
创建setup.py脚本,提供详细的关于build,使用等方法。
(v_python3.6) thinkt@linux-pw37:~/PycharmProjects/mysite/django-polls> vim setup.py
(v_python3.6) thinkt@linux-pw37:~/PycharmProjects/mysite/django-polls> cat 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',
],
)
创建附加文件说明。
v_python3.6) thinkt@linux-pw37:~/PycharmProjects/mysite/django-polls> vim MANIFEST.in
(v_python3.6) thinkt@linux-pw37:~/PycharmProjects/mysite/django-polls> cat MANIFEST.in
include LICENSE
include README.rst
recursive-include polls/static *
recursive-include polls/templates *
recursive-include docs *
附加文件有有个docs目录,创建docs目录,如果有文档等放置在其中。
(v_python3.6) thinkt@linux-pw37:~/PycharmProjects/mysite/django-polls> mkdir docs
开始打包。
(v_python3.6) thinkt@linux-pw37:~/PycharmProjects/mysite/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
writing top-level names to django_polls.egg-info/top_level.txt
writing manifest file 'django_polls.egg-info/SOURCES.txt'
reading manifest file 'django_polls.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching 'LICENSE'
warning: no files found matching '*' under directory 'polls/static'
warning: no files found matching '*' under directory 'polls/templates'
warning: no files found matching '*' under directory 'docs'
writing manifest file 'django_polls.egg-info/SOURCES.txt'
running check
creating django-polls-0.1
creating django-polls-0.1/django_polls.egg-info
creating django-polls-0.1/migrations
copying files to django-polls-0.1...
copying MANIFEST.in -> django-polls-0.1
copying README.rst -> django-polls-0.1
copying setup.py -> django-polls-0.1
copying django_polls.egg-info/PKG-INFO -> django-polls-0.1/django_polls.egg-info
copying django_polls.egg-info/SOURCES.txt -> django-polls-0.1/django_polls.egg-info
copying django_polls.egg-info/dependency_links.txt -> django-polls-0.1/django_polls.egg-info
copying django_polls.egg-info/top_level.txt -> django-polls-0.1/django_polls.egg-info
copying migrations/0001_initial.py -> django-polls-0.1/migrations
copying migrations/0002_auto_20170401_1758.py -> django-polls-0.1/migrations
copying migrations/__init__.py -> django-polls-0.1/migrations
Writing django-polls-0.1/setup.cfg
creating dist
Creating tar archive
removing 'django-polls-0.1' (and everything under it)
在dist目录下存放了打包好的文件。
(v_python3.6) thinkt@linux-pw37:~/PycharmProjects/mysite/django-polls/dist> ll
总用量 4
-rw-r--r-- 1 thinkt users 2349 4月 18 15:08 django-polls-0.1.tar.gz
使用pip安装本地打包。
pip install --user django-polls/dist/django-polls-0.1.tar.gz
使用pip的uninstall删除
pip uninstall django-polls
参考:https://docs.djangoproject.com/en/1.10/intro/reusable-apps/