Skip to content


Change the "format" GET parameter to be overridden in django settings. #703

wants to merge 2 commits into from

2 participants


"format' is a very easy field name to conflict with. Instead of forcing the user to use a different field name to resolve conflicts, I would like to allow the dev to be able to overwrite the format parameter name in settings.

My ultimate goal is to make the "format" parameter to default to something less likely to conflict (e.g. "_format"). That will be a different request, and may be a backwards-compatibility issue. So if we allow the format to be overridden, then I can just set it to "_format" on my project without a forked version of tastypie.


Thanks for the pull request. Before it could be merged, it would need tests, per our contribution guidelines.

I'm -1 on making this a setting. A Resource.Meta option would allow future APIs to use this, while not breaking existing APIs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 22, 2012
  1. Change default "format" to be a django setting.

    Craig Jackson committed
  2. Adjust the return message for the format parameter.

    Craig Jackson committed
Showing with 21 additions and 4 deletions.
  1. +14 −0 docs/settings.rst
  2. +2 −1 tastypie/
  3. +5 −3 tastypie/utils/
14 docs/settings.rst
@@ -98,3 +98,17 @@ An example::
Defaults to ``iso-8601``.
+This setting controls the format parameter name checked in API requests.
+An example::
+Defaults to ``format``.
3 tastypie/
@@ -432,7 +432,8 @@ def to_html(self, data, options=None):
options = options or {}
- return 'Sorry, not implemented yet. Please append "?format=json" to your URL.'
+ format_parameter = getattr(settings, 'TASTYPIE_FORMAT_PARAMETER', 'format')
+ return 'Sorry, not implemented yet. Please append "?' + format_parameter + '=json" to your URL.'
def from_html(self, content):
8 tastypie/utils/
@@ -1,5 +1,6 @@
import mimeparse
+from django.conf import settings
def determine_format(request, serializer, default_format='application/json'):
@@ -15,9 +16,10 @@ def determine_format(request, serializer, default_format='application/json'):
to ``application/json`` if not provided).
# First, check if they forced the format.
- if request.GET.get('format'):
- if request.GET['format'] in serializer.formats:
- return serializer.get_mime_for_format(request.GET['format'])
+ format_parameter = getattr(settings, 'TASTYPIE_FORMAT_PARAMETER', 'format')
+ if request.GET.get(format_parameter):
+ if request.GET[format_parameter] in serializer.formats:
+ return serializer.get_mime_for_format(request.GET[format_parameter])
# If callback parameter is present, use JSONP.
if request.GET.has_key('callback'):
Something went wrong with that request. Please try again.