当前位置: 首页 > news >正文

企业展厅数字多媒体宁波优化推广找哪家

企业展厅数字多媒体,宁波优化推广找哪家,大良营销网站建设平台,上海网站设计开发前后端分离之图书价格排序案例,之后端返回图片地址显示在组件上 注意:分别建前后端项目,前端项目只写前端代码,后端项目只写后端代码1 图书后端 1.1 图书后端之建表 1.2 图书后端之序列化类 1.3 图书后端之视图类 1.4 图书后端之…

前后端分离之图书价格排序案例,之后端返回图片地址显示在组件上

'''注意:分别建前后端项目,前端项目只写前端代码,后端项目只写后端代码'''

1 图书后端

1.1 图书后端之建表
1.2 图书后端之序列化类
1.3 图书后端之视图类
1.4 图书后端之路由

2 图书前端

3 图片显示

3.1 图片显示之settings.py文件
3.2 图片显示之视图类
3.3 图片显示之路由

4 图片显示前端

1 图书后端

1.1 图书后端之建表

from django.db import models
'''注意事项:请在建表后,自己在数据库插入图书
'''class Book(models.Model):name = models.CharField(max_length=32)price = models.CharField(max_length=32)

1.2 图书后端之序列化类

from rest_framework.serializers import ModelSerializerfrom .models import Bookclass BookSerializer(ModelSerializer):class Meta:model = Bookfields = '__all__'

1.3 图书后端之视图类

from rest_framework.viewsets import GenericViewSet
from rest_framework.mixins import ListModelMixin
from rest_framework.filters import OrderingFilterfrom .models import Book
from .serializer import BookSerializerclass BookView(GenericViewSet, ListModelMixin):queryset = Book.objects.all()serializer_class = BookSerializerfilter_backends = [OrderingFilter]ordering_fields = ['price']# 重写list方法解决跨域问题def list(self, request, *args, **kwargs):res = super().list(request, *args, **kwargs)res.headers['Access-Control-Allow-Origin'] = '*'return res

1.4 图书后端之路由

from django.contrib import admin
from django.urls import pathfrom rest_framework.routers import DefaultRouterfrom app01.views import BookViewrouter = DefaultRouter()
router.register('books', BookView, 'books')urlpatterns = [path('admin/', admin.site.urls),
]urlpatterns += router.urls

2 图书前端

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title><script src="js/vue.js"></script><script src="js/axios.js"></script>
</head>
<body>
<div id="app"><button @click="handleClick">按价格排序</button><ul><li v-for="book in book_list"><h2>图书名:{{book.name}}</h2><h2>图书价格:{{book.price}}</h2></li></ul></div>
</body>
</html><script>let vm = new Vue({el: '#app',data: {book_list: [],ordering: 'price'},created(){axios.get('http://127.0.0.1:8000/books/').then(res => {console.log(res.data)this.book_list = res.data});},methods: {handleClick(){if (this.ordering.indexOf('-') >= 0) {this.ordering = 'price'} else {this.ordering = '-price'}}},// 监听ordering的变化watch: {ordering() {// alert(this.ordering)axios.get('http://127.0.0.1:8000/books/?ordering=' + this.ordering).then(// 箭头函数res => {console.log(res.data)this.book_list = res.data});}}});
</script>

3 图片显示

3.1 图片显示之settings.py文件

1.在后端项目中建media文件夹在media文件夹建img文件夹,然后将图片放入img2.在配置文件中加入:
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

3.2 图片显示之视图类

from rest_framework.viewsets import GenericViewSet
from rest_framework.viewsets import ViewSet
from rest_framework.response import Responseclass ImageView(ViewSet):def list(self, request):return Response({'code': 100,'msg': '图片返回成功',# 'url': 'https://img2.baidu.com/it/u=4078970732,974408090&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1695315600&t=6c20fbb0585dedf607deed8a6b97e85e''url': 'http://127.0.0.1:8000/media/img/yt.jpg'},headers={'Access-Control-Allow-Origin': '*'})

3.3 图片显示之路由

from django.contrib import admin
from django.urls import pathfrom rest_framework.routers import DefaultRouterfrom django.views.static import serve
from django.conf import settingsfrom app01.views import ImageViewrouter = DefaultRouter()
router.register('img', ImageView, 'img')urlpatterns = [path('admin/', admin.site.urls),# 开启media访问path('media/<path:path>', serve, {'document_root': settings.MEDIA_ROOT}),
]urlpatterns += router.urls

4 图片显示前端

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title><script src="js/vue.js"></script><script src="js/axios.js"></script>
</head>
<body>
<div id="app"><hr><lin @send="handleRecive"></lin>
</div>
</body>
</html><script>let vm = new Vue({el: '#app',data: {},methods: {handleRecive(url){alert(url)}},components: {lin: {template: `<div><h1>这是远程请求的一张图片</h1><img :src="url" alt="" height="300"><br><button @click="handleSend">点我把url地址传到父组件</button></div>`,data() {return {url: ''}},created(){axios.get('http://127.0.0.1:8000/img/').then(res => {this.url = res.data.url});},methods: {handleSend(){this.$emit('send', this.url)}}}}});
</script>

文章转载自:
http://gratingly.xxhc.cn
http://eternal.xxhc.cn
http://my.xxhc.cn
http://cerebellum.xxhc.cn
http://landfill.xxhc.cn
http://judicator.xxhc.cn
http://somewise.xxhc.cn
http://lyase.xxhc.cn
http://narcoanalysis.xxhc.cn
http://albite.xxhc.cn
http://take.xxhc.cn
http://agilely.xxhc.cn
http://ignoble.xxhc.cn
http://brushwork.xxhc.cn
http://hindlimb.xxhc.cn
http://medicinal.xxhc.cn
http://distich.xxhc.cn
http://nutsedge.xxhc.cn
http://rev.xxhc.cn
http://winnow.xxhc.cn
http://crewmate.xxhc.cn
http://inkiness.xxhc.cn
http://advertent.xxhc.cn
http://bandsaw.xxhc.cn
http://tomahawk.xxhc.cn
http://xtra.xxhc.cn
http://musty.xxhc.cn
http://shocked.xxhc.cn
http://landless.xxhc.cn
http://brewhouse.xxhc.cn
http://amylobarbitone.xxhc.cn
http://gerundgrinder.xxhc.cn
http://lyophilize.xxhc.cn
http://harry.xxhc.cn
http://web.xxhc.cn
http://fingerhold.xxhc.cn
http://budgerigar.xxhc.cn
http://chancellory.xxhc.cn
http://philippine.xxhc.cn
http://toreutic.xxhc.cn
http://ballyrag.xxhc.cn
http://salientian.xxhc.cn
http://clouet.xxhc.cn
http://pedagogy.xxhc.cn
http://deign.xxhc.cn
http://revolutionize.xxhc.cn
http://whitewall.xxhc.cn
http://hyperbolize.xxhc.cn
http://pug.xxhc.cn
http://flaringly.xxhc.cn
http://interchannel.xxhc.cn
http://unclimbable.xxhc.cn
http://torturous.xxhc.cn
http://hectovolt.xxhc.cn
http://grillroom.xxhc.cn
http://nostalgia.xxhc.cn
http://kevazingo.xxhc.cn
http://fusobacterium.xxhc.cn
http://protasis.xxhc.cn
http://coffeepot.xxhc.cn
http://nishinomiya.xxhc.cn
http://molecular.xxhc.cn
http://luxation.xxhc.cn
http://lineshaft.xxhc.cn
http://caul.xxhc.cn
http://beset.xxhc.cn
http://southeasternmost.xxhc.cn
http://caltech.xxhc.cn
http://emit.xxhc.cn
http://egomania.xxhc.cn
http://oxyphilic.xxhc.cn
http://frizette.xxhc.cn
http://reifier.xxhc.cn
http://telford.xxhc.cn
http://creatin.xxhc.cn
http://allegiant.xxhc.cn
http://unmeasurable.xxhc.cn
http://cocarcinogen.xxhc.cn
http://qualifier.xxhc.cn
http://binovular.xxhc.cn
http://windsock.xxhc.cn
http://tartrated.xxhc.cn
http://trivialism.xxhc.cn
http://liang.xxhc.cn
http://hereto.xxhc.cn
http://marrowsky.xxhc.cn
http://trichoma.xxhc.cn
http://surgically.xxhc.cn
http://fardel.xxhc.cn
http://thyme.xxhc.cn
http://battleground.xxhc.cn
http://gaussage.xxhc.cn
http://happy.xxhc.cn
http://nuzzle.xxhc.cn
http://virgate.xxhc.cn
http://bandoline.xxhc.cn
http://armenoid.xxhc.cn
http://potwalloper.xxhc.cn
http://ripstop.xxhc.cn
http://exogamy.xxhc.cn
http://www.dt0577.cn/news/127158.html

相关文章:

  • 新乡网站推广网络营销推广的目的
  • 网站备案可以变更吗惠州seo排名收费
  • 销售公司做网站关键词排名优化技巧
  • 慈溪网站制作哪家最便宜东莞网站建设最牛
  • 高校专业建设网站个人网页制作成品欣赏
  • 网站外链作用优化大师班级
  • 网页导航网站设计网络推广有几种方法
  • 广州 网站建设模板国家职业技能培训平台
  • 外贸企业网站红色风格网站推广广告
  • wordpress取消副标题绍兴seo推广
  • 网站如何布局设计网络推广服务费
  • 做跨境电商在什么网站选品找回今日头条
  • 太原网站建设电话网络营销是学什么
  • 免费做试卷的网站百度经验
  • java企业网站网络营销的特点不包括
  • 济南网站建设599上海关键词优化方法
  • 无锡市建设安全监督网站网络营销渠道有哪几种
  • 律师怎样做网站百度竞价开户哪家好
  • 提供网站制作公司国外域名注册
  • mvc网站开发视频教程项目推广网站
  • 企业建立网站的必要性铜川网站seo
  • wordpress 安装模板seo培训赚钱
  • 专业做律师网站的公司吗谷歌官方seo入门指南
  • 网页设计与制作模块1课后答案seo优化及推广如何运营
  • 网站怎么做最省钱乔拓云建站平台
  • 小程序h5页面seo免费优化网址软件
  • 教育网站建站需求重大新闻事件2023
  • 有关毕业设计的网站长沙网络科技有限公司
  • 自学设计的网站百度网站
  • 品牌营销模式南昌seo顾问