aboutsummaryrefslogtreecommitdiffstats
path: root/docs/howto
diff options
context:
space:
mode:
Diffstat (limited to 'docs/howto')
-rw-r--r--docs/howto/reverse.rst39
-rw-r--r--docs/howto/setup.rst66
2 files changed, 81 insertions, 24 deletions
diff --git a/docs/howto/reverse.rst b/docs/howto/reverse.rst
new file mode 100644
index 00000000..73b8fa4d
--- /dev/null
+++ b/docs/howto/reverse.rst
@@ -0,0 +1,39 @@
+Returning URIs from your Web APIs
+=================================
+
+As a rule, it's probably better practice to return absolute URIs from you web APIs, e.g. "http://example.com/foobar", rather than returning relative URIs, e.g. "/foobar".
+
+The advantages of doing so are:
+
+* It's more explicit.
+* It leaves less work for your API clients.
+* There's no ambiguity about the meaning of the string when it's found in representations such as JSON that do not have a native URI type.
+* It allows us to easily do things like markup HTML representations with hyperlinks.
+
+Django REST framework provides two utility functions to make it simpler to return absolute URIs from your Web API.
+
+There's no requirement for you to use them, but if you do then the self-describing API will be able to automatically hyperlink its output for you, which makes browsing the API much easier.
+
+reverse(viewname, request, ...)
+-------------------------------
+
+The :py:func:`~reverse.reverse` function has the same behavior as `django.core.urlresolvers.reverse`_, except that it takes a request object and returns a fully qualified URL, using the request to determine the host and port::
+
+ from djangorestframework.reverse import reverse
+ from djangorestframework.views import View
+
+ class MyView(View):
+ def get(self, request):
+ context = {
+ 'url': reverse('year-summary', request, args=[1945])
+ }
+
+ return Response(context)
+
+reverse_lazy(viewname, request, ...)
+------------------------------------
+
+The :py:func:`~reverse.reverse_lazy` function has the same behavior as `django.core.urlresolvers.reverse_lazy`_, except that it takes a request object and returns a fully qualified URL, using the request to determine the host and port.
+
+.. _django.core.urlresolvers.reverse: https://docs.djangoproject.com/en/dev/topics/http/urls/#reverse
+.. _django.core.urlresolvers.reverse_lazy: https://docs.djangoproject.com/en/dev/topics/http/urls/#reverse-lazy
diff --git a/docs/howto/setup.rst b/docs/howto/setup.rst
index f14e0499..0af1449c 100644
--- a/docs/howto/setup.rst
+++ b/docs/howto/setup.rst
@@ -3,52 +3,70 @@
Setup
=====
-Installing into site-packages
------------------------------
+Templates
+---------
-If you need to manually install Django REST framework to your ``site-packages`` directory, run the ``setup.py`` script::
+Django REST framework uses a few templates for the HTML and plain text
+documenting renderers. You'll need to ensure ``TEMPLATE_LOADERS`` setting
+contains ``'django.template.loaders.app_directories.Loader'``.
+This will already be the case by default.
- python setup.py install
+You may customize the templates by creating a new template called
+``djangorestframework/api.html`` in your project, which should extend
+``djangorestframework/base.html`` and override the appropriate
+block tags. For example::
-Template Loaders
-----------------
+ {% extends "djangorestframework/base.html" %}
-Django REST framework uses a few templates for the HTML and plain text documenting renderers.
+ {% block title %}My API{% endblock %}
-* Ensure ``TEMPLATE_LOADERS`` setting contains ``'django.template.loaders.app_directories.Loader'``.
+ {% block branding %}
+ <h1 id="site-name">My API</h1>
+ {% endblock %}
-This will be the case by default so you shouldn't normally need to do anything here.
-Admin Styling
--------------
+Styling
+-------
-Django REST framework uses the admin media for styling. When running using Django's testserver this is automatically served for you,
-but once you move onto a production server, you'll want to make sure you serve the admin media separately, exactly as you would do
-`if using the Django admin <https://docs.djangoproject.com/en/dev/howto/deployment/modpython/#serving-the-admin-files>`_.
+Django REST framework requires `django.contrib.staticfiles`_ to serve it's css.
+If you're using Django 1.2 you'll need to use the seperate
+`django-staticfiles`_ package instead.
+
+You can override the styling by creating a file in your top-level static
+directory named ``djangorestframework/css/style.css``
-* Ensure that the ``ADMIN_MEDIA_PREFIX`` is set appropriately and that you are serving the admin media.
- (Django's testserver will automatically serve the admin media for you)
Markdown
--------
-The Python `markdown library <http://www.freewisdom.org/projects/python-markdown/>`_ is not required but comes recommended.
+`Python markdown`_ is not required but comes recommended.
+
+If markdown is installed your :class:`.Resource` descriptions can include
+`markdown formatting`_ which will be rendered by the self-documenting API.
+
+YAML
+----
+
+YAML support is optional, and requires `PyYAML`_.
-If markdown is installed your :class:`.Resource` descriptions can include `markdown style formatting
-<http://daringfireball.net/projects/markdown/syntax>`_ which will be rendered by the HTML documenting renderer.
-robots.txt, favicon, login/logout
----------------------------------
+Login / Logout
+--------------
-Django REST framework comes with a few views that can be useful including a deny robots view, a favicon view, and api login and logout views::
+Django REST framework includes login and logout views that are useful if
+you're using the self-documenting API::
from django.conf.urls.defaults import patterns
urlpatterns = patterns('djangorestframework.views',
- (r'robots.txt', 'deny_robots'),
- (r'favicon.ico', 'favicon'),
# Add your resources here
(r'^accounts/login/$', 'api_login'),
(r'^accounts/logout/$', 'api_logout'),
)
+.. _django.contrib.staticfiles: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/
+.. _django-staticfiles: http://pypi.python.org/pypi/django-staticfiles/
+.. _URLObject: http://pypi.python.org/pypi/URLObject/
+.. _Python markdown: http://www.freewisdom.org/projects/python-markdown/
+.. _markdown formatting: http://daringfireball.net/projects/markdown/syntax
+.. _PyYAML: http://pypi.python.org/pypi/PyYAML \ No newline at end of file