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/

Django项目打包的更多相关文章

  1. [django]项目打包构建

    django项目的结构大体上都是类似,打包主要的功能就是把一些不需要部署的文件剔除,把需要部署的文件直接压缩打包. 这里还想集成一个配置文件模板生成配置文件的过程,或者写一个配置文件生成的工具,不用每 ...

  2. Nginx+Uwsgi+Django 项目部署到服务器。

    首先先说一下思路: 1.本地django项目打包 主要用到的是 python自带的distutils.core 下的 setup,具体代码在下面,主要讲的两个问题是package主要打包为和目录同级的 ...

  3. 打包django项目

    1.安装pip install pyinstaller2.在django项目目录下执行pyi-makespec -D manage.py # 生成manage.spec文件3.执行pyinstalle ...

  4. [译]如何使用 Docker 组件开发 Django 项目?

    原文地址:Django Development With Docker Compose and Machine 以下为译文 Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包 ...

  5. 基于centos7+nginx+uwsgi+python3+django2.0部署Django项目

    0.序言 本文讲解如何基于centos7+nginx+uwsgi+python3+django2.0把windows上的本地项目部署到云服务器上. 本文服务器上的django项目和虚拟环境的路径将建立 ...

  6. Django APP打包重用

    引言 有时候,我们需要将自己写的app分发(dist)给同事,分享给朋友,或者在互联网上发布,这都需要打包.分发我们的app. Django的子系统重用是基于app级别的.也就是一个项目可以包含多个互 ...

  7. 直接运行vue+django项目

    直接运行vue+django项目 下载前后端代码 wget https://files.cnblogs.com/files/pyyu/luffy_boy.zip wget https://files. ...

  8. 使用Nginx+uwsgi在亚马逊云服务器上部署python+django项目完整版(二)——部署配置及相关知识

    ---恢复内容开始--- 一.前提: 1.django项目文件已放置在云服务器上,配置好运行环境,可正常运行 2.云服务器可正常连接 二.相关知识 1.python manage.py runserv ...

  9. 基于腾讯云CentOS7.4+MySQL5.7+Python3+uwsgi+nginx的Django项目部署

    准备知识 1.django一个基于python的开源web框架,请确保自己熟悉它的框架目录结构. 2.uWSGI一个基于自有的uwsgi协议.wsgi协议和http服务协议的web网关 3.nginx ...

随机推荐

  1. 微信网页授权,获取微信code,获取access_tocken,获取用户信息

    微信开发中,经常有这样的需求:获得用户头像.绑定微信号给用户发信息.. 那么实现这些的前提就是授权!   1.配置安全回调域名: 在微信公众号请求用户网页授权之前,开发者需要先到公众平台官网中的“开发 ...

  2. DOS命令集

    1.ASSOC显示或修改文件扩展名关联.ASSOC [.ext[=[fileType]]]  .ext      指定跟文件类型关联的文件扩展名  fileType  指定跟文件扩展名关联的文件类型键 ...

  3. KMP算法-从头到尾彻底理解KMP

    一:背景 给定一个主串(以 S 代替)和模式串(以 P 代替),要求找出 P 在 S 中出现的位置,此即串的模式匹配问题. Knuth-Morris-Pratt 算法(简称 KMP)是解决这一问题的常 ...

  4. Python设计模式(9)-外观模式

    # /*外观模式:为外界调用提供一个统一的接口,把其他类中需要用到的方法提取# * 出来,由外观类进行调用.然后在调用段实例化外观类,以间接调用需要的# * 方法.这种方式和代理模式有异曲同工之妙.然 ...

  5. python3(七)dict list

    # dict全称dictionary,在其他语言中也称为map,使用键-值(key-value)存储,具有极快的查找速度. # dict内部存放的顺序和key放入的顺序是没有关系的 # 根据同学的名字 ...

  6. leetcode Perform String Shifts

    Perform String Shifts You are given a string s containing lowercase English letters, and a matrix sh ...

  7. redis中的分布式锁

    分布式锁的实现场景 在平时的开发中,对于高并发的开发场景,我们不可避免要加锁进行处理,当然redis中也是不可避免的,下面是我总结出来的几种锁的场景 Redis分布式锁方案一 使用Redis实现分布式 ...

  8. Xray安装与使用

    0×00 Xray简介 xray是从长亭洞鉴核心引擎中提取出的社区版漏洞扫描神器,支持主动.被动多种扫描方式,自备盲打平台.可以灵活定义 POC,功能丰富,调用简单,支持 Windows / macO ...

  9. 如何提高你使用windows的逼格(windows用成Linux的赶脚)

    一.准备工作 作为一个整洁而有内涵的人,电脑桌面一定要清洁 二.桌面整洁了,软件怎么打开呢?     方案一 方案二.敲重点   我们可以使用终端指令打开windows安装的任意软件: 打开Windo ...

  10. Ant安装与配置

    1. 到apache 官网去下载最新版本的ant,http://ant.apache.org/:下载后直接解压缩到电脑上,不需要安装: 2.环境变量配置: 2.1 ->计算机右键->属性- ...