mirror of
https://github.com/django/django.git
synced 2025-08-04 19:08:28 +00:00
Fixed #20910 -- Added a "snippet" sphinx directive to allow prefixing a filename.
Thanks Marc Tamlyn for the suggestion.
This commit is contained in:
parent
e077224f4a
commit
d07d6ae116
10 changed files with 403 additions and 124 deletions
|
@ -120,112 +120,122 @@ this. For a small app like polls, this process isn't too difficult.
|
|||
1. First, create a parent directory for ``polls``, outside of your Django
|
||||
project. Call this directory ``django-polls``.
|
||||
|
||||
.. admonition:: Choosing a name for your app
|
||||
.. admonition:: Choosing a name for your app
|
||||
|
||||
When choosing a name for your package, check resources like PyPI to avoid
|
||||
naming conflicts with existing packages. It's often useful to prepend
|
||||
``django-`` to your module name when creating a package to distribute.
|
||||
This helps others looking for Django apps identify your app as Django
|
||||
specific.
|
||||
When choosing a name for your package, check resources like PyPI to avoid
|
||||
naming conflicts with existing packages. It's often useful to prepend
|
||||
``django-`` to your module name when creating a package to distribute.
|
||||
This helps others looking for Django apps identify your app as Django
|
||||
specific.
|
||||
|
||||
2. Move the ``polls`` directory into the ``django-polls`` directory.
|
||||
|
||||
3. Create a file ``django-polls/README.rst`` with the following contents::
|
||||
3. Create a file ``django-polls/README.rst`` with the following contents:
|
||||
|
||||
=====
|
||||
Polls
|
||||
=====
|
||||
.. snippet::
|
||||
:filename: django-polls/README.rst
|
||||
|
||||
Polls is a simple Django app to conduct Web-based polls. For each
|
||||
question, visitors can choose between a fixed number of answers.
|
||||
=====
|
||||
Polls
|
||||
=====
|
||||
|
||||
Detailed documentation is in the "docs" directory.
|
||||
Polls is a simple Django app to conduct Web-based polls. For each
|
||||
question, visitors can choose between a fixed number of answers.
|
||||
|
||||
Quick start
|
||||
-----------
|
||||
Detailed documentation is in the "docs" directory.
|
||||
|
||||
1. Add "polls" to your INSTALLED_APPS setting like this::
|
||||
Quick start
|
||||
-----------
|
||||
|
||||
INSTALLED_APPS = (
|
||||
...
|
||||
'polls',
|
||||
)
|
||||
1. Add "polls" to your INSTALLED_APPS setting like this::
|
||||
|
||||
2. Include the polls URLconf in your project urls.py like this::
|
||||
INSTALLED_APPS = (
|
||||
...
|
||||
'polls',
|
||||
)
|
||||
|
||||
url(r'^polls/', include('polls.urls')),
|
||||
2. Include the polls URLconf in your project urls.py like this::
|
||||
|
||||
3. Run `python manage.py migrate` to create the polls models.
|
||||
url(r'^polls/', include('polls.urls')),
|
||||
|
||||
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).
|
||||
3. Run `python manage.py migrate` to create the polls models.
|
||||
|
||||
5. Visit http://127.0.0.1:8000/polls/ to participate in the poll.
|
||||
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 a license is beyond the
|
||||
scope of this tutorial, but suffice it to say that code released publicly
|
||||
without a license is *useless*. Django and many Django-compatible apps are
|
||||
distributed under the BSD license; however, you're free to pick your own
|
||||
license. Just be aware that your licensing choice will affect who is able
|
||||
to use your code.
|
||||
scope of this tutorial, but suffice it to say that code released publicly
|
||||
without a license is *useless*. Django and many Django-compatible apps are
|
||||
distributed under the BSD license; however, you're free to pick your own
|
||||
license. Just be aware that your licensing choice will affect who is able
|
||||
to use your code.
|
||||
|
||||
5. Next we'll create a ``setup.py`` file which provides details about how to
|
||||
build and install the app. A full explanation of this file is beyond the
|
||||
scope of this tutorial, but the `distribute docs
|
||||
<http://packages.python.org/distribute/setuptools.html>`_ have a good explanation.
|
||||
Create a file ``django-polls/setup.py`` with the following contents::
|
||||
build and install the app. A full explanation of this file is beyond the
|
||||
scope of this tutorial, but the `distribute docs
|
||||
<http://packages.python.org/distribute/setuptools.html>`_ have a good
|
||||
explanation. Create a file ``django-polls/setup.py`` with the following
|
||||
contents:
|
||||
|
||||
import os
|
||||
from setuptools import setup
|
||||
.. snippet::
|
||||
:filename: django-polls/setup.py
|
||||
|
||||
README = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read()
|
||||
import os
|
||||
from setuptools import setup
|
||||
|
||||
# allow setup.py to be run from any path
|
||||
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))
|
||||
README = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read()
|
||||
|
||||
setup(
|
||||
name='django-polls',
|
||||
version='0.1',
|
||||
packages=['polls'],
|
||||
include_package_data=True,
|
||||
license='BSD License', # example license
|
||||
description='A simple Django app to conduct Web-based polls.',
|
||||
long_description=README,
|
||||
url='http://www.example.com/',
|
||||
author='Your Name',
|
||||
author_email='yourname@example.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 using Python 3
|
||||
'Programming Language :: Python :: 2',
|
||||
'Programming Language :: Python :: 2.7',
|
||||
'Topic :: Internet :: WWW/HTTP',
|
||||
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
|
||||
],
|
||||
)
|
||||
# allow setup.py to be run from any path
|
||||
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))
|
||||
|
||||
.. admonition:: I thought you said we were going to use ``distribute``?
|
||||
setup(
|
||||
name='django-polls',
|
||||
version='0.1',
|
||||
packages=['polls'],
|
||||
include_package_data=True,
|
||||
license='BSD License', # example license
|
||||
description='A simple Django app to conduct Web-based polls.',
|
||||
long_description=README,
|
||||
url='http://www.example.com/',
|
||||
author='Your Name',
|
||||
author_email='yourname@example.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 using Python 3
|
||||
'Programming Language :: Python :: 2',
|
||||
'Programming Language :: Python :: 2.7',
|
||||
'Topic :: Internet :: WWW/HTTP',
|
||||
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
|
||||
],
|
||||
)
|
||||
|
||||
Distribute is a drop-in replacement for ``setuptools``. Even though we
|
||||
appear to import from ``setuptools``, since we have ``distribute``
|
||||
installed, it will override the import.
|
||||
.. admonition:: I thought you said we were going to use ``distribute``?
|
||||
|
||||
Distribute is a drop-in replacement for ``setuptools``. Even though we
|
||||
appear to import from ``setuptools``, since we have ``distribute``
|
||||
installed, it will override the import.
|
||||
|
||||
6. Only Python modules and packages are included in the package by default. To
|
||||
include additional files, we'll need to create a ``MANIFEST.in`` file. The
|
||||
distribute docs referred to in the previous step discuss this file in more
|
||||
details. To include the templates, the ``README.rst`` and our ``LICENSE``
|
||||
file, create a file ``django-polls/MANIFEST.in`` with the following
|
||||
contents::
|
||||
contents:
|
||||
|
||||
include LICENSE
|
||||
include README.rst
|
||||
recursive-include polls/static *
|
||||
recursive-include polls/templates *
|
||||
.. snippet::
|
||||
:filename: django-polls/MANIFEST.in
|
||||
|
||||
include LICENSE
|
||||
include README.rst
|
||||
recursive-include polls/static *
|
||||
recursive-include polls/templates *
|
||||
|
||||
7. It's optional, but recommended, to include detailed documentation with your
|
||||
app. Create an empty directory ``django-polls/docs`` for future
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue