Noreversematch with Keywords Arguments even if there is a route

Asked

Viewed 34 times

1

I am trying to send an id to the url using Xios with the following line:

const request = axios.put("{% url 'forms:save' card_id=card.card_id %}", this.body_text_value).then(response =>{ console.log(this)})

and in my urls.py is like this:

path('save/<int:card_id>', views.save, name="save"),

but I keep getting the bug

Reverse for 'save' with keyword arguments '{'card_id': ''}' not found. 1 pattern(s) tried: ['forms/save/(?P<id>[0-9]+)$']

I will leave here my Vue Component and view.py downstairs in case you need to:

Vue.component('input-body', {
        template: '<textarea class="form-control body-input" placeholder="Digite um texto para o seu card :)" type="text" name="card_bodytext" v-model="body_text_value" v-on:blur="save" style="height: 300px" > </textarea>',
        props: ['body'],
        data(){
            return{
                body_text_value: this.body 
            }
        },
        methods: {

            save(){
                axios.defaults.xsrfCookieName = 'csrftoken'
                axios.defaults.xsrfHeaderName = "X-CSRFTOKEN"
                const request = axios.put("{% url 'forms:save' id=card.id %}", this.body_text_value).then(response =>{ console.log(this)})
            }
        }
    })


    new Vue({
        delimiters: ["[[", "]]"],
        el: '.cards',
        });

views.py


def boards(request):
    cards = Card.objects.all()
    card_id = Card.card_id
    title = Card.title
    body_text = Card.body_text
    last_modify = Card.last_modify

    return render(request, template_name='forms/card_model.html', context={
        'card_id': card_id,
        'title': title,
        'body_text': body_text,
        'cards': cards,
        'last_modify': last_modify
        })

EDIT 1

"Change variables with ID name" Now it only changed the argument giving error.

  • My ready suggestion is to rename the variable id because it’s Python’s reserved word. Then update the post

  • @Paulomarques Tu diz como contexto, a variável dentro da view, no modelo ou todas as opções?

  • @Gabrielo, inside the view when you do id = Card.id you should use another variable name, such as card_id for example, why id in python is a method that returns the identity of an object

  • I suggest you do it in whole place that appears id = alguma_coisa

  • @Paulomarques Cara... I switched and did not solve.

  • @Flaviomoraes Yes, that’s what I did. But it didn’t solve...

  • @Gabrielo, update the post with the new code.

  • @Paulomarques ready to go

  • Try to change from const request = axios.put("{% url 'forms:save' card_id=card.card_id %}", this.body_text_value).then(response =>{ console.log(this)}) for const request = axios.put("{% url 'forms:save' card.card_id %}", this.body_text_value).then(response =>{ console.log(this)})

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.