Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8700841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:15:42+00:00 2026-06-13T02:15:42+00:00

I’m trying to implement a simple Django service with a RESTful API using tastypie.

  • 0

I’m trying to implement a simple Django service with a RESTful API using tastypie. My problem is that when I try to create a WineResource with PUT, it works fine, but when I use POST, it returns a HTTP 501 error. Reading the tastypie documentation, it seems like it should just work, but it’s not.

Here’s my api.py code:

    class CustomResource(ModelResource):
    """Provides customizations of ModelResource"""
    def determine_format(self, request):
    """Provide logic to provide JSON responses as default"""
    if 'format' in request.GET:
        if request.GET['format'] in FORMATS:
        return FORMATS[request.GET['format']]
        else:
        return 'text/html' #Hacky way to prevent incorrect formats
    else:
        return 'application/json'

class WineValidation(Validation):
    def is_valid(self, bundle, request=None):
    if not bundle.data:
        return {'__all__': 'No data was detected'}

    missing_fields = []
    invalid_fields = []

    for field in REQUIRED_WINE_FIELDS:
        if not field in bundle.data.keys():
        missing_fields.append(field)
    for key in bundle.data.keys():
        if not key in ALLOWABLE_WINE_FIELDS:
        invalid_fields.append(key)

    errors = missing_fields + invalid_fields if request.method != 'PATCH' \
        else invalid_fields

    if errors:
        return 'Missing fields: %s; Invalid fields: %s' % \
            (', '.join(missing_fields), ', '.join(invalid_fields))
    else:
        return errors

class WineProducerResource(CustomResource):
    wine = fields.ToManyField('wines.api.WineResource', 'wine_set', 
                 related_name='wine_producer')
    class Meta:
    queryset = WineProducer.objects.all()
    resource_name = 'wine_producer'
    authentication = Authentication() #allows all access
    authorization = Authorization() #allows all access

class WineResource(CustomResource):
    wine_producer = fields.ForeignKey(WineProducerResource, 'wine_producer')

    class Meta:
    queryset = Wine.objects.all()
    resource_name = 'wine'
    authentication = Authentication() #allows all access
    authorization = Authorization() #allows all access
    validation = WineValidation()
    filtering = {
        'percent_new_oak': ('exact', 'lt', 'gt', 'lte', 'gte'),
        'percentage_alcohol': ('exact', 'lt', 'gt', 'lte', 'gte'),
        'color': ('exact', 'startswith'),
        'style': ('exact', 'startswith')

    }

    def hydrate_wine_producer(self, bundle):
    """Use the provided WineProducer ID to properly link a PUT, POST,
    or PATCH to the correct WineProducer instance in the db"""
    #Workaround since tastypie has bug and calls hydrate more than once
    try:
        int(bundle.data['wine_producer'])
    except ValueError:
        return bundle
    bundle.data['wine_producer'] = '/api/v1/wine_producer/%s/' % \
                        bundle.data['wine_producer']
    return bundle

Any help is greatly appreciated! 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:15:44+00:00Added an answer on June 13, 2026 at 2:15 am

    This usually means that you are sending the POST to a detail uri, e.g. /api/v1/wine/1/. Since POST means treat the enclosed entity as a subordinate, sending the POST to the list uri, e.g. /api/v1/wine/, is probably what you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
I'm making a simple page using Google Maps API 3. My first. One marker
Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.