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– Paulo Marques
@Paulomarques Tu diz como contexto, a variável dentro da view, no modelo ou todas as opções?
– GabrielO
@Gabrielo, inside the view when you do
id = Card.id
you should use another variable name, such ascard_id
for example, whyid
in python is a method that returns the identity of an object– Flavio Moraes
I suggest you do it in whole place that appears
id = alguma_coisa
– Paulo Marques
@Paulomarques Cara... I switched and did not solve.
– GabrielO
@Flaviomoraes Yes, that’s what I did. But it didn’t solve...
– GabrielO
@Gabrielo, update the post with the new code.
– Paulo Marques
@Paulomarques ready to go
– GabrielO
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)})
forconst request = axios.put("{% url 'forms:save' card.card_id %}", this.body_text_value).then(response =>{ console.log(this)})
– Paulo Marques