Navigation

This is a guide how to create first third-party django library or application, attempting to be kindly.
Django documentation tell you way to create django’s projects and applications.
But there isn’t (perhaps) way to distribute applications like django-cms, django-blog-zinnia.
So, I’ll show you it.

Whole example project described on this page is on Github: django-myapp.

This guide includes about packaging or python environments.
If you have created couple of python libraries, you can skip over some steps
to 3. Way to run tests without projects.
But at least, I expect you to finish the tutorial of
django’s document and create some apps.

When you create third-party library, you won’t need to create a project.
Just create your application by using startapp sub-command.
But wait. you will distribute this application, so you need a parent directory to package it
like this:

mkdirdjango-myappcddjango-myappdjango-admin.pystartappmyapp

OK, just it. Write your codes as same as way you learned at tutorial.
“Can’t run tests”...? Yeah, I know it. and I’ll show you about it later.

And you need to write README and LICENSE file to describe about your package.
I won’t use packages without README or documentation:

To distribute your app/lib, make it as a package.
Just thing you need to do is putting setup.py file under the django-myapp directory
meaning next to myapp directory.

The contents of this file will contain information about your package, name, version,
description, required packages, and so on:

importosfromsetuptoolsimportsetuphere=os.path.abspath(os.path.dirname(__file__))README=open(os.path.join(here,'README.rst')).read()setup(name='django-myapp',version='0.1',packages=['myapp'],description='A line of description',long_description=README,author='yourname',author_email='yourname@example.com',url='https://github.com/yourname/django-myapp/',license='MIT',install_requires=['Django>=1.6,<1.7',])

I recommend you to write them at least.

name

The name of package like django-cms. This name will use when you specify the package by pip.
So if you name it as django-myapp, users will type pip install django-myapp.

It’s over.
After created setup.py, run this command to register this new package for development:

pythonsetup.pydevelop

For more detail about setup.py, please refer another documents or packages.
Python Packaging User Guide will help you.
And I imitated setup.py of some another packages. Actually I haven’t read documents so much.

If you want to upload your package to PyPI. just register the application and upload:

Basically django always requires ‘projects’ for all of actions. then how can we run tests?
actually It’s easy, you can just use django-admin.py command and specify settings file for testing.
First, create the settings for testing on the project root: