My html code is (ser.html)
<div>
<a v-bind:href="'ser/'+post.name">
{{post.name}}</a>
</div>
I need to pass post.name from this file to other ie.(det.html)
My views.py is
from django.shortcuts import render
import os
def ser(request):
return render(request,"ser.html",{});
def det(request):
return render(request,"det.html",{'name' :name});
My urls.py is
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^abt', views.abt),
url(r'^$', views.index),
url(r'^ser',views.ser),
url(r'^det',views.det),
]
My det.html has following code
<script>
mounted() {
var self = this;
$.ajax({
url: 'post/filter/',
data: {
category: {{name}},
},
type: "POST",
dataType: 'json',
success: function (e) {
if (e.status == 1) {
window.searchContent.vector = e.data;
console.log(e);
}
}
});
</script>
I need to pass 'name' to this det.html category in order to fire the ajax request. But when I do this way I am getting error. This is my project using python and vue js. Can anybody please help me?
Error is:
missing 1 required positional argument: 'name'
In your
view.pyfile the render has no clue where to get thenamevariable from. Here is one way to fix it: You can pass thenameparameter fromser.htmlto the backend as GET param:Then in your
view.pyfile, get the name variable:In
det.htmlit will be available.If you'd like to do it with POST request, change the ser.html to run a VueJS function, something like this:
In the VueJS object implement the method funcToPost to do the POST call, something like this:
In view.py change
request.GET.get('name')torequest.POST.get('name').Hope this solves your problem. Good luck.