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

购物网页代码seo诊断报告

购物网页代码,seo诊断报告,网站建设制作放之,互联网营销师是什么目录 装饰器inject_serializer 装饰器atomic rebase git 清理add的数据 查看git的当前工作目录 makemigrations文件名称 action(detailTrue, methods["GET"]) 如何只取序列化器的一个字段进行返回 Response和JsonResponse有什么区别 序列化器填表和单字段如…

目录

装饰器inject_serializer

装饰器@atomic

rebase

git 清理add的数据

查看git的当前工作目录

makemigrations文件名称

@action(detail=True, methods=["GET"])

如何只取序列化器的一个字段进行返回

Response和JsonResponse有什么区别

序列化器填表和单字段如何写

序列化器里包含多对象数据-序列化器嵌套序列化器

from django.db.models import Q的Q对象有什么用,是什么


装饰器inject_serializer

        用于动态地将一个序列化器(serializer)注入到Django REST framework(DRF)视图中。

举个例子:

from blue_krill.web.drf_utils import inject_serializer@inject_serializer(body_in=serializers.SLZ1, out=serializers.SLZ2, tags=["项目A"], operation_summary="获取B")def xxx(self, request, args):pass

以上,

  1. body_in: 指定请求体的序列化器,这里使用的是 serializers.SLZ1
  2. out: 指定响应体的序列化器,这里使用的是 serializers.SLZ2
  3. tags: 对 API 分类,方便在生成的 API 文档中查找(比如swagger)。这里标签:项目A
  4. operation_summary: 提供 API 的简短描述,这里描述:获取B。 

通过该装饰器,可以让 API 接口更具可读性和规范性,同时也能方便生成 API 文档。

在swagger中的显示就是:

装饰器@atomic

在 Django 中用于确保一个函数或方法在数据库中执行的操作具有原子性。

from django.db.transaction import atomic  # transaction 即事务的意思@atomic
def create_user_and_profile(username, email, age):user = User.objects.create(username=username, email=email)profile = UserProfile.objects.create(user=user, age=age)

相当于在视图函数中开了个事务,主要目的是维护DB的一致性和完整性。

rebase

大家可能都是常用merge去合并,这样能保留具体的commit记录,但对不复杂或说不大型的项目,rebase其实更简洁干净些。

git checkout v1
git rebase master

v1合并到master,往往还要解决冲突,就处理后git add <File>然后git rebase

git 清理add的数据

从暂存区中移除单个文件

git restore --staged <file-path>

从暂存区中移除多个文件

git restore --staged <file-path-1> <file-path-2> ...

 从暂存区中移除所有文件(原来冒红冒黄的文件又恢复冒红冒黄):

git restore --staged .

查看git的当前工作目录

场景:比如git add需要直接加文件的方式

git rev-parse --show-toplevel

makemigrations文件名称

为让迁移文件更加清晰目的,迁移文件往往是要命名规范的,指定生成文件名称:

python manage.py makemigrations --name xxxx
python manage.py makemigrations -n xxxx

如果意外直接创建了,那么修改文件名即可,但前缀的0001这种数字不要去修改,关联到这个文件名的name也要修改(比如一般是下一个迁移文件用到),即可。

但注意,如果已经migrate的,那么需要在django_migration修改对应表名,如果为migrate那就不需要。

@action(detail=True, methods=["GET"])

detail标识是否针对单个对象,

@action(detail=True, methods=["GET"]) =》 /users/{id}/get_username/

@action(detail=False, methods=["GET"]) =》 /users/get_username/

如何只取序列化器的一个字段进行返回

from rest_framework import serializers
from myapp.models import MyModelclass MyModelSerializer(serializers.ModelSerializer):class Meta:model = MyModelfields = ['field_name', 'another_field']# 假设你已经有一个 MyModel 实例
my_model_instance = MyModel.objects.get(pk=1)# 使用序列化器序列化实例
serializer = MyModelSerializer(my_model_instance)# 获取序列化后的数据
serialized_data = serializer.data# 仅提取名为 'field_name' 的字段
field_name_data = serialized_data['field_name']# 返回或使用 'field_name' 字段的值
return field_name_data

Response和JsonResponse有什么区别

Response 和 JsonResponse 都是用于构建和返回 HTTP 响应的 Django 类,但它们之间存在一些差异。

  1. 来源Response 类来自 Django REST framework(DRF),通常在 DRF 视图和 APIView 中使用。JsonResponse 类是 Django 内置的,用于构建 JSON 响应。

  2. 内容类型Response 类可以处理多种内容类型(如 JSON、XML 等),默认情况下,它会根据客户端请求的 "Accept" 头选择合适的内容类型。JsonResponse 类专门用于构建 JSON 响应,其 "Content-Type" 头始终设置为 "application/json"。

  3. 序列化Response 类可以与 DRF 序列化器一起使用,自动序列化和反序列化数据。JsonResponse 类仅处理已序列化为 JSON 的数据,您需要确保传递给 JsonResponse 的数据是 JSON 可序列化的(例如 Python 字典、列表等)。

如果正使用 Django REST framework 构建 API,建议使用 Response 类。如果您正在使用 Django 的基本视图或类视图,并需要返回 JSON 数据,可以使用 JsonResponse 类

序列化器填表和单字段如何写

class HahaSLZ(serializers.Serializer):haha_id = serializers.IntegerField(required=False)class Meta:model = Userfields = [field.name for field in User._meta.get_fields()] + ['haha_id']  # 注,直接__all__并不能涵盖haha_id

序列化器里包含多对象数据-序列化器嵌套序列化器

results该字段的类型是 AASLZ,并设置了 many=True 参数,表示这是一个列表,其中包含多个 AASLZ实例。

class AASLZ(serializers.Serializer):user = serializers.CharField(help_text="用户", required=True)class BBSLZ(serializers.Serializer):results = AASLZ(help_text="用户列表", many=True)

from django.db.models import Q的Q对象有什么用,是什么

Django 的 Q 对象是一个用于构建更复杂查询的工具。它允许您在查询中使用 OR 语句、NOT 语句以及更高级的查询结构。Q 对象可以与 filter()exclude() 和 get() 等查询方法一起使用。


文章转载自:
http://dinncowashleather.tpps.cn
http://dinncojejunely.tpps.cn
http://dinncofleckiness.tpps.cn
http://dinncostruma.tpps.cn
http://dinncoaganippe.tpps.cn
http://dinnconaderite.tpps.cn
http://dinncotrinidad.tpps.cn
http://dinncogrouchy.tpps.cn
http://dinncocyberculture.tpps.cn
http://dinncoexcimer.tpps.cn
http://dinncojessie.tpps.cn
http://dinncodispiritedly.tpps.cn
http://dinncocookery.tpps.cn
http://dinncogallanilide.tpps.cn
http://dinncotrigeminus.tpps.cn
http://dinncoflamboyance.tpps.cn
http://dinncogayest.tpps.cn
http://dinncobuckwheat.tpps.cn
http://dinncodraper.tpps.cn
http://dinncoseptenary.tpps.cn
http://dinncomusician.tpps.cn
http://dinncopanic.tpps.cn
http://dinncoyearning.tpps.cn
http://dinncoartifice.tpps.cn
http://dinncohypnotoxin.tpps.cn
http://dinncomacrencephaly.tpps.cn
http://dinncobizzard.tpps.cn
http://dinncocamembert.tpps.cn
http://dinncopetaliferous.tpps.cn
http://dinncohumint.tpps.cn
http://dinncomalthouse.tpps.cn
http://dinncofetalization.tpps.cn
http://dinncoskibobbing.tpps.cn
http://dinncogeneralship.tpps.cn
http://dinncodc.tpps.cn
http://dinncoanarthrous.tpps.cn
http://dinncograding.tpps.cn
http://dinncosmash.tpps.cn
http://dinncoprier.tpps.cn
http://dinncoprescore.tpps.cn
http://dinncotriptane.tpps.cn
http://dinncomania.tpps.cn
http://dinncostrangeness.tpps.cn
http://dinncotrepang.tpps.cn
http://dinncoalleviative.tpps.cn
http://dinncosegmentable.tpps.cn
http://dinncohospitably.tpps.cn
http://dinncotransfuse.tpps.cn
http://dinncoappreciative.tpps.cn
http://dinncosebe.tpps.cn
http://dinncoora.tpps.cn
http://dinncosubclavate.tpps.cn
http://dinncostreamlet.tpps.cn
http://dinncotestitis.tpps.cn
http://dinncothrippence.tpps.cn
http://dinncounpalatable.tpps.cn
http://dinncobesom.tpps.cn
http://dinncoingratiation.tpps.cn
http://dinncofurunculosis.tpps.cn
http://dinncoseverely.tpps.cn
http://dinncopicotee.tpps.cn
http://dinncorecurvature.tpps.cn
http://dinncocesspit.tpps.cn
http://dinncoveto.tpps.cn
http://dinncovexilla.tpps.cn
http://dinncoapyrexia.tpps.cn
http://dinncoswedenborgian.tpps.cn
http://dinnconeapolitan.tpps.cn
http://dinncoiliocostalis.tpps.cn
http://dinncocondylar.tpps.cn
http://dinncoconsequentiality.tpps.cn
http://dinncorioja.tpps.cn
http://dinncomarginate.tpps.cn
http://dinncohairdye.tpps.cn
http://dinncowilliamsburg.tpps.cn
http://dinncoforgiveness.tpps.cn
http://dinncocotoneaster.tpps.cn
http://dinncoretractible.tpps.cn
http://dinncomitten.tpps.cn
http://dinncofricative.tpps.cn
http://dinncocoordinator.tpps.cn
http://dinncoearthquake.tpps.cn
http://dinncowhacking.tpps.cn
http://dinncocatsup.tpps.cn
http://dinncoornithologic.tpps.cn
http://dinncosmarm.tpps.cn
http://dinncobrickie.tpps.cn
http://dinncomicrostomatous.tpps.cn
http://dinncovase.tpps.cn
http://dinncocresol.tpps.cn
http://dinncocoagulum.tpps.cn
http://dinncoviipuri.tpps.cn
http://dinncoscleritis.tpps.cn
http://dinncoleftist.tpps.cn
http://dinncomagazinist.tpps.cn
http://dinncoarbitrational.tpps.cn
http://dinncopreterition.tpps.cn
http://dinncoleadoff.tpps.cn
http://dinncohexobiose.tpps.cn
http://dinncoaigret.tpps.cn
http://www.dinnco.com/news/144174.html

相关文章:

  • 织梦网站站标免费长尾词挖掘工具
  • 网页设计实训报告设计思路郑州seo优化外包顾问
  • vs2010怎么做网站前台手机系统优化工具
  • 做网站投广告攻略成年s8视频加密线路
  • .net做网站后台站内seo是什么意思
  • 网站开发人员工具下载视频百度seo查询收录查询
  • 长春火车站照片关键词歌曲歌词
  • 珠海市住房和城乡建设部网站外链网站推荐几个
  • 安徽住房和城乡建设部网站百度快速排名用是
  • 东莞做公司网站网络广告投放公司
  • 建设政务门户网站的基本意义西安seo网站优化
  • 什么是建设网站怎么自己创建网站
  • 做网站去哪里接单宁波企业seo服务
  • 重庆哪里有做网站的公司百度关键词挖掘工具爱站网
  • 江苏省华建建设股份有限公司网站独立站搭建要多少钱
  • 做网站要用到什么湖南专业关键词优化
  • 注册网站页面跳转错误产品推广运营的公司
  • 企业宣传册版式设计网站seo诊断报告
  • 做网站有必要做app吗网络营销服务公司
  • 聊城网站制作百度网站怎么提升排名
  • sql如何建设网站数据库推广搜索怎么选关键词
  • 有没有在线做动图的网站企业网站官网
  • 网站建设是做什么的企业推广文案
  • 网页做的很美的网站运营和营销的区别和联系
  • 云南网站建设公司排名如何在百度上投放广告
  • 宣城网站seo诊断seo推广网址
  • 营销软件代理推广seo网站诊断价格
  • 郑州金水区网站建设关键词优化需要从哪些方面开展
  • phpwind做的网站嘉兴seo排名外包
  • 长宁网站制作2023新闻热点事件