Reusable Django Packages/Apps: Difference between revisions

From Littledamien Wiki
Jump to navigation Jump to search
(Created page with "== Overview == Notes on workflow and best practices for creating and maintaining reusable packages/apps in Django.<ref>[https://docs.djangoproject.com/en/1.8/intro/reusable-a...")
 
Line 4: Line 4:


== Workflow ==
== Workflow ==
=== Packaging an app ===
<syntaxhighlight lang="bash">
$ cd /path/to/app/source/dir/
$ python setup.py sdist
</syntaxhighlight>
=== Installing, uninstalling, and updating apps ===
<syntaxhighlight lang="bash">
$ pip uninstall django-addresses
$ pip install ~/develop/labs/shared/django-addresses/dist/django-addresses-1.2.1.tar.gz
</syntaxhighlight>
Make sure to take at all the versions stored in the `dist` directory to confirm that the latest version is being installed, i.e. don't assume that there is only one version stored there.
=== Using an app in a Django project ===
Add the app name under `INSTALLED_APPS` in the project's `settings.py` file.
<syntaxhighlight lang="python" highlight="12">
# my_project/settings.py
# ...
INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiels',
    'contact_info',
)
</syntaxhighlight>


=== Confirming the version of an installed app ===
=== Confirming the version of an installed app ===

Revision as of 18:01, 1 September 2015

Overview

Notes on workflow and best practices for creating and maintaining reusable packages/apps in Django.[1]

Workflow

Packaging an app

$ cd /path/to/app/source/dir/
$ python setup.py sdist

Installing, uninstalling, and updating apps

$ pip uninstall django-addresses
$ pip install ~/develop/labs/shared/django-addresses/dist/django-addresses-1.2.1.tar.gz

Make sure to take at all the versions stored in the dist directory to confirm that the latest version is being installed, i.e. don't assume that there is only one version stored there.

Using an app in a Django project

Add the app name under INSTALLED_APPS in the project's settings.py file.

# my_project/settings.py

# ...

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiels',
    'contact_info',
)

Confirming the version of an installed app

Use the pip show command, e.g.:

$ pip show django-contact_info

Notes

  1. How to write reusable apps - Django Documentation