Packaging and application installation and uninstallation for Django applications

Source: Internet
Author: User

To install the app package requires installation: Setuptools

Installing and uninstalling apps requires installation: PIP

Example polls is an app package. The polls folder contains all the files about the app.

Packaging apps:

  1. Firstly, outside of your Django project, polls to create a parent directory. django-polls .

    Choose a name for your app

    When you choose a name for your package , check the resources in the PyPI to avoid name collisions with existing packages. When creating a package to publish, precede your module name with django- is often useful.   This helps other people who are looking for Django apps to differentiate your app specifically for Django.

    The applied label (the final part of the point of the applied package) in installed_apps Must be unique in the. Avoid using the same tags as any of the Django contrib package  , such as , admin and messages .

  2. polls   Directory moved to django-polls directory.

  3. Create a file containing some content django-polls/ Readme.rst :

    Django-polls/readme.rst
     =====polls=====polls is a simple Django app to conduct Web-based polls. For eachquestion, 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. 
  4. Create a django-polls/license file. Choosing License is beyond the scope of this tutorial, but it is worth saying that the publicly released code is useless without license. Django and many Django-compliant apps are released in BSD License; However, you can pick your own License. just know that your license choice will affect who can use your code.

  5. Next we will create a setup.py file that provides detailed information on how to build and install the app. The full explanation of the file is beyond the scope of this tutorial, and the Setuptools documentation is well explained. Create a file django-polls/setup.pywith the following contents:

    django-polls/setup.py
    ImportOsFromSetuptoolsImportSetupWithOpen(Os.Path.Join(Os.Path.DirName(__file__),' Readme.rst '))AsReadme: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-polls ',Version=' 0.1 ',Packages=[' Polls '],Include_package_data=True,License=' BSD License ',# example LicenseDescription=' A simple Django app to conduct web-based polls. ',Long_description=Readme,Url=' http://www.example.com/',Author=' Your Name ',Author_email=' [Email protected] ',classifiers=[' Environment:: WEB Environment ',' Framework:: Django ' "intended audience:: Developers '  ' License:: OSI Approved:: BSD License ' # example License  ' Operating System:: OS indep Endent '  ' programming Language:: Python ' # Replace These appropriately if you is 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 ' ],)          
  6. by default only Python modules and packages are included in the package. If you need to include additional files, we need to create a manifest.in file. readme.rst and our license   file, create a file django-polls/manifest.in , which reads as follows:

    django-polls/manifest.in
     include Licenseinclude readme.rstrecursive-include polls/static *recursive-include polls/templates * 
  7. It is optional to include detailed documentation into your application, but it is recommended that you do so. Create an empty directory Django-polls/docs for storing documents in the future. Add another line to django-polls/manifest.in :

    Recursive-include Docs *

    Note that docs will not be included in your package unless you add some files underneath it. Many Django applications also provide their online documentation through sites such as readthedocs.org.

  8. Try building your package from the setup.py sdist in Python (run from inside the django-polls ). This creates a dist directory and builds a new package:django-polls-0.1.tar.gz.

For more information on packaging, see the tutorials for packaging and distributing items in Python.

To install and uninstall your own package:

Because we moved the polls directory out of the project directory, it no longer works. We will fix it by installing our new Django-polls package.

A library that is installed as a user

The following steps will install the django-polls into a user's library. User-level installations have many advantages over system-level installations, such as running packages at the normal user level without impacting system services and not affecting other users

Note Depending on the user's installation, System tools that run as the user can still be affected, so virtualenv is a more robust solution (see below).

    1. Install this package and use PIP (you've already installed it, right?). ):

      Pip Install--user django-polls/dist/django-polls-0.1.tar.gz
    2. Fortunately, your Django project should now be working again. Please rerun the server to confirm this.

    3. To uninstall this package, use PIP:

      Pip Uninstall Django-polls

Packaging and application installation and uninstallation for Django applications

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.