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 7820069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:09:41+00:00 2026-06-02T07:09:41+00:00

Whenever I do a model.destroy() with Backbone, it tries to do a DELETE request

  • 0

Whenever I do a model.destroy() with Backbone, it tries to do a DELETE request on the following URL:

http://localhost:8000/api/v1/item/?format=json

Since I am doing a destroy on a model, I would expect that the ID of the model should be passed, so the URL to do a DELETE request on would be this:

http://localhost:8000/api/v1/item/8/?format=json

where the ID is specified. Because of the lack of ID, and my use of tastypie, all items get deleted. How do I make it so that the URL contains the ID of the item that I wish to delete?

  • 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-02T07:09:42+00:00Added an answer on June 2, 2026 at 7:09 am

    I’m guessing that your model looks something like this:

    var M = Backbone.Model.extend({
        url: '/api/v1/item/?format=json',
        // ...
    });
    

    The url for a model is supposed to be a function but, since it ends up going through the internal getValue function, a string will also “work”; if you check the source I linked to, you’ll see why a string for url would give you the results you’re seeing.

    The solution is to use a function for url as you’re supposed to:

    url model.url()

    Returns the relative URL where the model’s resource would be located on the server. If your models are located somewhere else, override this method with the correct logic. Generates URLs of the form: "/[collection.url]/[id]", falling back to "/[urlRoot]/id" if the model is not part of a collection.

    You’d probably want something like this:

    url: function() {
        if(this.isNew())
            return '/api/v1/item/?format=json';
        return '/api/v1/item/' + encodeURIComponent(this.id) + '/?format=json';
    }
    

    or this:

    url: function() {
        if(this.isNew())
            return '/api/v1/item/?format=json';
        return '/api/v1/item/' + encodeURIComponent(this.get('id')) + '/?format=json';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume a Backbone model with the following attributes: - subtotal - discount - total
I'm trying to add a new virtual field to my backbone model whenever a
My Model has the following field. It has to update whenever there is a
Hello I have a user model and a ratings model. Whenever a new user
I want to use a autocomplete combobox http://jqueryui.com/demos/autocomplete/#combobox within a modal dialog. However whenever
With Entity Framework, whenever I update model from database inside Visual Studio the model
I have the following model entity: public class ScheduledTask { public virtual int ScheduledTaskId
I just need to send a mail notification whenever a model is deleted. I
Using Google App Engine and Django. Whenever I have a db.ReferenceProperty() inside a model
Whenever I console.log() a Backbone.js Collection, Google Chrome's console shows the letter d unlike

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.