2011-02-19 16:12:35 +03:00
|
|
|
.. _setup:
|
|
|
|
|
|
|
|
Setup
|
|
|
|
=====
|
|
|
|
|
2012-02-21 00:31:41 +04:00
|
|
|
Templates
|
|
|
|
---------
|
2011-06-02 16:34:23 +04:00
|
|
|
|
2012-02-21 00:31:41 +04:00
|
|
|
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.
|
2011-06-02 16:34:23 +04:00
|
|
|
|
2012-02-21 00:31:41 +04:00
|
|
|
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::
|
2012-02-15 05:31:56 +04:00
|
|
|
|
2012-02-20 17:16:51 +04:00
|
|
|
{% extends "djangorestframework/base.html" %}
|
2012-02-15 05:31:56 +04:00
|
|
|
|
|
|
|
{% block title %}My API{% endblock %}
|
|
|
|
|
|
|
|
{% block branding %}
|
|
|
|
<h1 id="site-name">My API</h1>
|
|
|
|
{% endblock %}
|
|
|
|
|
|
|
|
|
2012-02-21 00:31:41 +04:00
|
|
|
Styling
|
|
|
|
-------
|
|
|
|
|
|
|
|
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``
|
|
|
|
|
|
|
|
|
2011-02-19 16:12:35 +03:00
|
|
|
Markdown
|
|
|
|
--------
|
|
|
|
|
2012-02-21 00:31:41 +04:00
|
|
|
`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`_.
|
2011-02-19 16:12:35 +03:00
|
|
|
|
|
|
|
|
2012-02-21 00:31:41 +04:00
|
|
|
Login / Logout
|
|
|
|
--------------
|
2011-02-19 16:28:21 +03:00
|
|
|
|
2012-02-21 00:31:41 +04:00
|
|
|
Django REST framework includes login and logout views that are useful if
|
|
|
|
you're using the self-documenting API::
|
2011-02-19 16:28:21 +03:00
|
|
|
|
|
|
|
from django.conf.urls.defaults import patterns
|
|
|
|
|
|
|
|
urlpatterns = patterns('djangorestframework.views',
|
|
|
|
# Add your resources here
|
|
|
|
(r'^accounts/login/$', 'api_login'),
|
|
|
|
(r'^accounts/logout/$', 'api_logout'),
|
|
|
|
)
|
|
|
|
|
2012-02-21 00:31:41 +04:00
|
|
|
.. _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
|