mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-23 10:03:57 +03:00
Fixing up browseable API for rest framework 2
This commit is contained in:
parent
f1dc9be5fc
commit
b8559c6192
|
@ -10,6 +10,7 @@ from django.template import RequestContext, loader
|
|||
from django.utils import simplejson as json
|
||||
|
||||
from djangorestframework.compat import yaml
|
||||
from djangorestframework.settings import api_settings
|
||||
from djangorestframework.utils import dict2xml
|
||||
from djangorestframework.utils import encoders
|
||||
from djangorestframework.utils.breadcrumbs import get_breadcrumbs
|
||||
|
@ -344,6 +345,7 @@ class DocumentingTemplateRenderer(BaseRenderer):
|
|||
'post_form': post_form_instance,
|
||||
'FORMAT_PARAM': self._FORMAT_QUERY_PARAM,
|
||||
'METHOD_PARAM': getattr(self.view, '_METHOD_PARAM', None),
|
||||
'api_settings': api_settings
|
||||
})
|
||||
|
||||
ret = template.render(context)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
{{ description }}
|
||||
|
||||
HTTP/1.0 {{ response.status }} {{ response.status_text }}
|
||||
HTTP {{ response.status }} {{ response.status_text }}
|
||||
{% for key, val in response.headers.items %}{{ key }}: {{ val }}
|
||||
{% endfor %}
|
||||
{{ content }}{% endautoescape %}
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
{% load url from future %}
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
{% load urlize_quoted_links %}
|
||||
{% load add_query_param %}
|
||||
{% load optional_login %}
|
||||
{% load static %}
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<link rel="stylesheet" type="text/css" href='{% get_static_prefix %}djangorestframework/css/style.css'/>
|
||||
{% block extrastyle %}{% endblock %}
|
||||
<title>{% block title %}Django REST framework - {{ name }}{% endblock %}</title>
|
||||
{% block extrahead %}{% endblock %}
|
||||
<head>
|
||||
<link rel="stylesheet" type="text/css" href='{% get_static_prefix %}djangorestframework/css/style.css'/>
|
||||
{% block extrastyle %}{% endblock %}
|
||||
<title>{% block title %}Django REST framework - {{ name }}{% endblock %}</title>
|
||||
{% block extrahead %}{% endblock %}
|
||||
{% block blockbots %}<meta name="robots" content="NONE,NOARCHIVE" />{% endblock %}
|
||||
</head>
|
||||
<body class="{% block bodyclass %}{% endblock %}">
|
||||
|
@ -37,19 +37,19 @@
|
|||
<div class="breadcrumbs">
|
||||
{% block breadcrumbs %}
|
||||
{% for breadcrumb_name, breadcrumb_url in breadcrumblist %}
|
||||
<a href="{{ breadcrumb_url }}">{{ breadcrumb_name }}</a> {% if not forloop.last %}›{% endif %}
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
</div>
|
||||
<a href="{{ breadcrumb_url }}">{{ breadcrumb_name }}</a> {% if not forloop.last %}›{% endif %}
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
</div>
|
||||
|
||||
<!-- Content -->
|
||||
<div id="content" class="{% block coltype %}colM{% endblock %}">
|
||||
<!-- Content -->
|
||||
<div id="content" class="{% block coltype %}colM{% endblock %}">
|
||||
|
||||
{% if 'OPTIONS' in allowed_methods %}
|
||||
{% if 'OPTIONS' in allowed_methods and api_settings.FORM_METHOD_OVERRIDE %}
|
||||
<form action="{{ request.get_full_path }}" method="post">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="{{ METHOD_PARAM }}" value="OPTIONS" />
|
||||
<input type="submit" value="OPTIONS" class="default" />
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="{{ api_settings.FORM_METHOD_OVERRIDE }}" value="OPTIONS" />
|
||||
<input type="submit" value="OPTIONS" class="default" />
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
|
@ -57,7 +57,7 @@
|
|||
<h1>{{ name }}</h1>
|
||||
<p>{{ description }}</p>
|
||||
<div class='module'>
|
||||
<pre><b>{{ response.status_code }} {{ response.status_text }}</b>{% autoescape off %}
|
||||
<pre><b>HTTP {{ response.status_code }} {{ response.status_text }}</b>{% autoescape off %}
|
||||
{% for key, val in response.items %}<b>{{ key }}:</b> {{ val|urlize_quoted_links }}
|
||||
{% endfor %}
|
||||
{{ content|urlize_quoted_links }}</pre>{% endautoescape %}</div>
|
||||
|
@ -78,21 +78,24 @@
|
|||
</form>
|
||||
{% endif %}
|
||||
|
||||
{% comment %}
|
||||
DROP POST/PUT/DELETE until the forms are working with REST framework 2
|
||||
|
||||
{# Only display the POST/PUT/DELETE forms if method tunneling via POST forms is enabled and the user has permissions on this view. #}
|
||||
{% if METHOD_PARAM and response.status_code != 403 %}
|
||||
{% if response.status_code != 403 %}
|
||||
|
||||
{% if 'POST' in allowed_methods %}
|
||||
<form action="{{ request.get_full_path }}" method="post" {% if post_form.is_multipart %}enctype="multipart/form-data"{% endif %}>
|
||||
<form action="{{ request.get_full_path }}" method="POST" {% if post_form.is_multipart %}enctype="multipart/form-data"{% endif %}>
|
||||
<fieldset class='module aligned'>
|
||||
<h2>POST {{ name }}</h2>
|
||||
{% csrf_token %}
|
||||
{{ post_form.non_field_errors }}
|
||||
{% csrf_token %}
|
||||
{{ post_form.non_field_errors }}
|
||||
{% for field in post_form %}
|
||||
<div class='form-row'>
|
||||
{{ field.label_tag }}
|
||||
{{ field }}
|
||||
<span class='help'>{{ field.help_text }}</span>
|
||||
{{ field.errors }}
|
||||
{{ field.label_tag }}
|
||||
{{ field }}
|
||||
<span class='help'>{{ field.help_text }}</span>
|
||||
{{ field.errors }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
<div class='submit-row' style='margin: 0; border: 0'>
|
||||
|
@ -102,42 +105,43 @@
|
|||
</form>
|
||||
{% endif %}
|
||||
|
||||
{% if 'PUT' in allowed_methods %}
|
||||
<form action="{{ request.get_full_path }}" method="post" {% if put_form.is_multipart %}enctype="multipart/form-data"{% endif %}>
|
||||
{% if 'PUT' in allowed_methods and api_settings.FORM_METHOD_OVERRIDE %}
|
||||
<form action="{{ request.get_full_path }}" method="POST" {% if put_form.is_multipart %}enctype="multipart/form-data"{% endif %}>
|
||||
<fieldset class='module aligned'>
|
||||
<h2>PUT {{ name }}</h2>
|
||||
<input type="hidden" name="{{ METHOD_PARAM }}" value="PUT" />
|
||||
<input type="hidden" name="{{ api_settings.FORM_METHOD_OVERRIDE }}" value="PUT" />
|
||||
{% csrf_token %}
|
||||
{{ put_form.non_field_errors }}
|
||||
{% for field in put_form %}
|
||||
<div class='form-row'>
|
||||
{{ field.label_tag }}
|
||||
{{ field }}
|
||||
<span class='help'>{{ field.help_text }}</span>
|
||||
{{ field.errors }}
|
||||
{{ field.label_tag }}
|
||||
{{ field }}
|
||||
<span class='help'>{{ field.help_text }}</span>
|
||||
{{ field.errors }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
<div class='submit-row' style='margin: 0; border: 0'>
|
||||
<input type="submit" value="PUT" class="default" />
|
||||
<input type="submit" value="PUT" class="default" />
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
{% if 'DELETE' in allowed_methods %}
|
||||
<form action="{{ request.get_full_path }}" method="post">
|
||||
{% if 'DELETE' in allowed_methods and api_settings.FORM_METHOD_OVERRIDE %}
|
||||
<form action="{{ request.get_full_path }}" method="POST">
|
||||
<fieldset class='module aligned'>
|
||||
<h2>DELETE {{ name }}</h2>
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="{{ METHOD_PARAM }}" value="DELETE" />
|
||||
<input type="hidden" name="{{ api_settings.FORM_METHOD_OVERRIDE }}" value="DELETE" />
|
||||
<div class='submit-row' style='margin: 0; border: 0'>
|
||||
<input type="submit" value="DELETE" class="default" />
|
||||
<input type="submit" value="DELETE" class="default" />
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
||||
{% endcomment %}
|
||||
</div>
|
||||
<!-- END content-main -->
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user