数据传输回顾

简单一些传输查询

models M

class Shop(models.Model):

name = models.CharField(max_length=32)

views V

def shop_list(request):

shops = Shop.objects.all()

return render(request,"shop_list.html",locals())

html T

<ul>

扫描二维码关注公众号,回复: 6038089 查看本文章

{% for shop in shops %}

<li>{{ shop.name }}</li>

{% endfor %}

</ul>

urls C

path("shop_list",shop_list)

将用到数据绑定的时候

models M

class Shop(models.Model):

name = models.CharField(max_length=32)

views V 获取数据

def shop_list(request):

shops = Shop.objects.all()

list_shop = []

for shop in shops:

list_shop.append(

{“name”:shop.name}

)

{"result":[{1},{2}]}

return JsonResponse({"result":list_shop})

urls C

path("shop_list",shop_list)

views V 展示页面

def show_shop(request):

return render(request,"show_shop.html",locals())

show_shop.html

{% verbatim myblock %}

<ul id = "content">

<li v-for="shop in page_data "> {{ shop.name }} </li>

<a v-bind:href="'xq/'+shop.name">哈哈哈哈哈</a>

</ul>

<ul>

{% endverbatim myblock %}

Vue.use(VueResource)

var vue = new Vue(

{

"el": "#content",

"data":[

page_data: []

],

created: function(){

this.$.http.get("shop_list").then(

function(data){

this.page_data = data["data"]["result"]

},

function(error){

}

)

},

methods: functions(){

}

}

)

猜你喜欢

转载自blog.csdn.net/weixin_44303465/article/details/89520028
今日推荐