django 如何重用app
2024-09-02 14:21:38
若有一个已经运行稳定的程序,那么可以将其打包,供其他项目安装使用。
假设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
最新文章
- JavaMail发送邮件的笔记及Demo
- 关于JSP页面字段属性设为disabled或者readonly所带来的问题总结
- angularjs-$interval使用
- 无序数组的中位数(set+deque)hdu5249
- c# Random Class usage
- ASP.NET CompareValidator 控件在VS2012中出错的问题
- 详细介绍如何使用kindEditor编辑器
- 关于Django模板渲染一个很重要的用途
- Struts2, jquery, select二级联动
- 开源一个上架 App Store 的相机 App
- Android 屏幕刷新机制
- SUSE10的虚拟机安装以及ORACLE 11g的安装
- bzoj1497 最小割
- The MathType Dll cannot be found 问题解决办法
- PHP eval函数
- c:url标签
- mysql8.0关闭log-bin功能
- Java中HashSet的解读
- windows上memecache添加多个端口命令
- 沉淀,再出发:web前端的一些认识