django - Django admin TabularInline “502 Bad Gateway” nginx 过早关闭连接
问题描述
我已经看到很多关于此的讨论,但没有任何帮助。下面是我得到的错误
*9 upstream prematurely closed connection while reading response header from upstream
它发生在我的 Django TabularInline 管理视图中。其他一切都工作得很好。
如果我在 TargetTabularInline 中进行此更改,它会起作用,
fields = (‘reviewed’,)
我相信这个问题是因为目标模型在其他表上有个人外键。这就是超时的地方。请告知我该如何解决这个问题?
管理员.py
class TargetTabularInline(admin.TabularInline):
model = Target
class VideoAdmin(admin.ModelAdmin):
inlines = [TargetTabularInline]
list_display = ['title', 'source', 'reviewed', 'category', 'sfw']
search_fields = ('title', 'category', 'source__name', 'reviewed', )
class Meta:
model = Video
admin.site.register(Video, VideoAdmin)
模型.py
class Video(DFModel):
source = models.ForeignKey(Source, models.DO_NOTHING)
creator = models.ForeignKey(
Creator, models.DO_NOTHING, blank=True, null=True)
title = models.CharField(max_length=500)
views = models.IntegerField(blank=True, null=True)
likes = models.IntegerField(blank=True, null=True)
dislikes = models.IntegerField(blank=True, null=True)
tags = models.TextField(blank=True, null=True)
upload_date = models.DateTimeField(blank=True, null=True)
page_url = models.TextField(blank=True, null=True)
video_url = models.TextField(blank=True, null=True)
thumb_url = models.TextField(blank=True, null=True)
sfw = models.BooleanField(blank=True, null=True)
category = models.CharField(max_length=20, blank=True, null=True)
reviewed = models.TextField(blank=True, null=True)
severity = models.CharField(max_length=10, blank=True, null=True)
origin = models.CharField(max_length=20, blank=True, null=True)
organization_id = models.IntegerField(blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True, blank=True, null=True)
class Target(DFModel):
person = models.ForeignKey(
Person, models.DO_NOTHING, blank=True, null=True)
video = models.ForeignKey(
'Video', models.DO_NOTHING, blank=True, null=True)
reviewed = models.TextField(blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True, blank=True, null=True)
class Meta:
db_table = ‘target'
解决方案
您的 Person 模型(或 Creator)可能有太多条目,管理员在查看管理员详细信息页面仪表板中的特定条目时试图在下拉菜单中加载这些条目,这会导致服务器负载过大
您可以将其添加到 VideoAdmin 类
raw_id_fields = ("creator",)
# OR
readonly_fields = ('creator',)
https://docs.djangoproject.com/en/3.0/ref/contrib/admin/#django.contrib.admin.ModelAdmin.raw_id_fields https://docs.djangoproject.com/en/3.0/ref/contrib/admin/ #django.contrib.admin.ModelAdmin.readonly_fields
这不会加载整个创建者表,这将减少服务器上的负载,并且工作人员将可以自由地处理其他请求。
如果 Person 表中有太多条目,也将其添加到 Target 管理员。
推荐阅读
- node.js - 在 CI / CD 管道中运行 cypress 测试的最佳实践是什么?
- laravel - 如何将所有 laravel 异常消息写入特定文件。如模型异常
- swiftui - 使用 Swift UI 将 CLLocationManager 的代表放在哪里?
- botframework - BotComposer,如何使用 lg 语言遍历字符串的字符?
- machine-learning - 计算kmeans模型的准确度得分
- react-native - 如何在 android studio 上运行 expo 弹出的应用程序
- python - 使用python在表格中显示csv数据
- c++ - 在 C++ 中声明 const 对象需要用户定义的默认构造函数。如果我有一个可变成员变量,为什么不呢?
- typescript - vue-class-component 和 Mixins
- excel - 如何在群组中查找最近的日期