博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Django H1 高级教程:如何编写可重用的应用
阅读量:4452 次
发布时间:2019-06-07

本文共 4590 字,大约阅读时间需要 15 分钟。

http://python.usyiyi.cn/translate/django_182/intro/reusable-apps.html

 

可重用很重要

  你在教程 2中创建了mysite/templates ,在教程 3中创建了polls/templates。 现在你可能更加清晰为什么我们为项目和应用选择单独的模板目录:属于投票应用的部分全部在polls中。它使得该应用“自包含(self-contained)”且更加容易丢到一个新的项目中。

 

  Python 打包的目前状态因为有多种工具而混乱不堪。对于本教程,我们打算使用来构建我们的包。它是推荐的打包工具(已经与distribute 分支合并)  

 

打包你的应用

step 1 

  mkdir django-tasks

  mv tasks django-tasks

$ cat django-tasks/MANIFEST.in include LICENSEinclude README.rstrecursive-include tasks/static *recursive-include tasks/templates *recursive-include docs *$mkdir django-tasks/doc$touch django-tasks/README.rst$$ cat django-tasks/setup.py #!/usr/bin/env python#-*- coding: utf-8 -*-__author__ = 'Ye Lin'__date__ = '17-2-10'import osfrom setuptools import setupwith open(os.path.join(os.path.dirname(__file__), 'README.rst')) as readme:    README = readme.read()# allow setup.py to be run from any pathos.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))setup(    name='django-tasks',    version='0.1',    packages=['tasks'],    include_package_data=True,    license='BSD License',  # example license    description='A simple Django app to conduct Web-based tasks.',    long_description=README,    url='http://www.example.com/',    author='ZSR',    author_email='lynn_0401@163.com',    classifiers=[        'Environment :: Web Environment',        'Framework :: Django',        '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.2',        'Programming Language :: Python :: 3.3',        'Topic :: Internet :: WWW/HTTP',        'Topic :: Internet :: WWW/HTTP :: Dynamic Content',    ],)$$ python setup.py sdistrunning sdistrunning egg_infowriting django_tasks.egg-info/PKG-INFOwriting top-level names to django_tasks.egg-info/top_level.txtwriting dependency_links to django_tasks.egg-info/dependency_links.txtreading manifest file 'django_tasks.egg-info/SOURCES.txt'reading manifest template 'MANIFEST.in'warning: no files found matching 'LICENSE'warning: no files found matching '*' under directory 'docs'writing manifest file 'django_tasks.egg-info/SOURCES.txt'running checkcreating django-tasks-0.1creating django-tasks-0.1/django_tasks.egg-infocreating django-tasks-0.1/taskscreating django-tasks-0.1/tasks/staticcreating django-tasks-0.1/tasks/static/taskscreating django-tasks-0.1/tasks/templatescreating django-tasks-0.1/tasks/templates/taskscopying files to django-tasks-0.1...copying MANIFEST.in -> django-tasks-0.1copying README.rst -> django-tasks-0.1copying setup.py -> django-tasks-0.1copying django_tasks.egg-info/PKG-INFO -> django-tasks-0.1/django_tasks.egg-infocopying django_tasks.egg-info/SOURCES.txt -> django-tasks-0.1/django_tasks.egg-infocopying django_tasks.egg-info/dependency_links.txt -> django-tasks-0.1/django_tasks.egg-infocopying django_tasks.egg-info/top_level.txt -> django-tasks-0.1/django_tasks.egg-infocopying tasks/__init__.py -> django-tasks-0.1/taskscopying tasks/admin.py -> django-tasks-0.1/taskscopying tasks/apps.py -> django-tasks-0.1/taskscopying tasks/models.py -> django-tasks-0.1/taskscopying tasks/tests.py -> django-tasks-0.1/taskscopying tasks/urls.py -> django-tasks-0.1/taskscopying tasks/views.py -> django-tasks-0.1/taskscopying tasks/static/tasks/style.css -> django-tasks-0.1/tasks/static/taskscopying tasks/templates/tasks/detail.html -> django-tasks-0.1/tasks/templates/taskscopying tasks/templates/tasks/index.html -> django-tasks-0.1/tasks/templates/taskscopying tasks/templates/tasks/results.html -> django-tasks-0.1/tasks/templates/tasksWriting django-tasks-0.1/setup.cfgCreating tar archiveremoving 'django-tasks-0.1' (and everything under it)

  

使用自己的包

$pip install --user django-tasks/dist/django-tasks-0.1.tar.gz Unpacking ./django-tasks/dist/django-tasks-0.1.tar.gz  Running setup.py (path:/tmp/pip-y8B6hl-build/setup.py) egg_info for package from file:///home/ly/PycharmProjects/ltest/django-tasks/dist/django-tasks-0.1.tar.gz    warning: no files found matching 'LICENSE'    warning: no files found matching '*' under directory 'docs'  Requirement already satisfied (use --upgrade to upgrade): django-tasks==0.1 from file:///home/ly/PycharmProjects/ltest/django-tasks/dist/django-tasks-0.1.tar.gz in /home/ly/.local/lib/python2.7/site-packagesCleaning up...

  

pip uninstall django-polls

转载于:https://www.cnblogs.com/zsr0401/p/6387102.html

你可能感兴趣的文章
POJ 2689 Prime Distance (素数筛选法,大区间筛选)
查看>>
HDU 4901 多校4 经典计数DP
查看>>
iOS通过dSYM文件分析crash
查看>>
使用行为树(Behavior Tree)实现游戏AI
查看>>
[转]解读Unity中的CG编写Shader系列二
查看>>
学生管理系统的优化过程
查看>>
魔都之行
查看>>
【OpenCV & CUDA】OpenCV和Cuda结合编程
查看>>
【译】索引列,列选择率和等式谓词
查看>>
activeMQ启动失败61616port被占用问题
查看>>
linux下oracle11G DG搭建(三):环绕备库搭建操作
查看>>
rsync配置文件的参数详解
查看>>
简单题
查看>>
MySQL(十)操纵表及全文本搜索
查看>>
begin again
查看>>
VS2008.Net下使用WPF开发Web应用程序小例
查看>>
数据库设计三大范式
查看>>
步步为营——算法初阶 1.算法概述
查看>>
Linux网络基本配置命令
查看>>
docker开启api端口,docker启用加速
查看>>