本文共 3037 字,大约阅读时间需要 10 分钟。
项目中往往需要将一个应用进行可重复的使用, 我们可以直接借助python对django应用程序进行打包, 打包完成后,再其他模块里引入打包的模块就可以将一个应用到处引入到其他模块里了。
=====Polls=====Polls is a 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.
[metadata]name = django-pollsversion = 0.1description = A Django app to conduct Web-based polls.long_description = file: README.rsturl = https://www.example.com/author = Your Nameauthor_email = yourname@example.comlicense = BSD-3-Clause # Example licenseclassifiers = Environment :: Web Environment Framework :: Django Framework :: Django :: X.Y # Replace "X.Y" as appropriate Intended Audience :: Developers License :: OSI Approved :: BSD License Operating System :: OS Independent Programming Language :: Python Programming Language :: Python :: 3 Programming Language :: Python :: 3 :: Only Programming Language :: Python :: 3.6 Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 Topic :: Internet :: WWW/HTTP Topic :: Internet :: WWW/HTTP :: Dynamic Content[options]include_package_data = truepackages = find:
include LICENSEinclude README.rstrecursive-include polls/static *recursive-include polls/templates *
recursive-include docs *
python -m pip install --user django-polls/dist/django-polls-0.1.tar.gz
成功后,会出现如下提示:
想卸载应用?
python -m pip uninstall django-polls
找到对应的资源后,将2个文件夹放入到Python的全局环境中:
怎么使用?
from polls.models import User
启动报错? 需要在settings.py文件里添加模块polls:
INSTALLED_APPS = [ 'simpleui', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'polls']
转载地址:http://buwb.baihongyu.com/