除非指定端口,否则 Django2.2 部分数据(错误内容长度不匹配)
Django2.2 partial data unless port specified (ERR CONTENT LENGTH MISMATCH)
原文:
滚动查看最新的,这是原来的post
数据 table 似乎只在直接导航到我在 http://server.com:9001 的 Django Web 应用程序时才有效,即使我已将所有 HTTP 流量代理到 9001。
从 http://server.com:9001/stores 查看时的屏幕截图
从 http://server.com/stores 查看时的屏幕截图
数据table只是简单地拒绝工作。更奇怪的是我在 /servers 有另一个数据 table 做同样的事情,但在 /closed-stores 有一个相同的 table 始终如一地工作(我已经连续刷新了几十次,试图让它崩溃,但它不会)。
每个 table 的 JS 都是简单的 $('#table-id').Datatable();
但我会忽略它,因为它显然可以工作,所以我相信它是我的 Nginx.conf 也许吧,或者与 Django 有关?
我还会注意到,在所有情况下,控制台中都出现 0 个错误。
Nginx.conf
server {
listen 80 default_server;
#listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
proxy_pass http://127.0.0.1:9001;
}
location /static {
autoindex on;
alias /home/usr/applications/it-database/static/;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
值得注意的是,这些 table 在我的 Windows Server 2016 开发服务器上运行了将近 2 个月没有出现任何问题,但是当迁移到 CentOS 时,这种情况开始出现。我只包括这个,因为我完全不知道问题可能是什么。
更新 1:
经过一番挖掘后,我发现问题是出于某种原因,我的 context 数据以某种方式被切断了。如果我指定端口号,我得到所有完整的数据,因此table可以转换为数据table,但当我不指定端口号时,数据将被截断店铺386(时多时少,一直在这个区)
我可以看到在某些版本的 Chrome 中,访问 /stores/
端点会出现 net::ERR_CONTENT_LENGTH_MISMATCH
错误。许多人说,对于以前的版本,这是由于中间件订单引起的,但此后已得到解决。
我的中间件:
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
/商店/视图:
@login_required
def stores(request):
stores = Store.objects.exclude(street_address__contains="closed").all()
context = {
'stores':stores,
}
return render(request, 'all_stores.html', context)
商店模板:
{% extends 'base.html' %}
{% block title %} All Stores - Stores Database {% endblock %}
{% block body %}
<br>
<div class="flex_container">
<h2>Store Database</h2>
<div class="table_header" style="float: left; position: relative;">
<br>
<h4>All Locations</h4>
</div>
<table id="store-table" class="table-striped table-hover">
<thead class="thead-light">
<tr>
<th>Store #</th>
<th>Name</th>
<th>Phone</th>
<th>City</th>
<th>State</th>
<th>Zip Code</th>
<th>Circuit</th>
</tr>
</thead>
<tbody>
{% for store in stores %}
<tr id="table-row">
<td><a href="/stores/{{ store.pk }}">{{ store.store_number }}</a></td>
<td><a href="/stores/{{ store.pk }}">{{ store.name }}</a></td>
<td>{{ store.phone }}</td>
<td>{{ store.city }}</td>
<td>{{ store.state }}</td>
<td>{{ store.postal }}</td>
<td>
{% for circuit in store.circuit_set.all %}
<p>{{ circuit.circuit_id }}</p>
{% endfor %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
<script>
$(document).ready(function () {
$('#store-table').DataTable();
});
</script>
{% endblock %}
这里的问题不一定与 Django 相关,但更多的是 Nginx 如何通过交付静态内容来处理代理。当你为静态文件设置一个 proxy_pass 时,你需要验证你的 nginx 用户是否可以访问 /lib/nginx/proxy_tmp
。您的用户可能还需要访问其他重要目录,因此我只是授予了整个 /lib/nginx
目录的所有权。
它在指定端口时传送的原因是因为我直接访问我的 Gunicorn/Django 应用程序,而不是通过 Nginx 代理,所以这个代理目录在那种情况下是不相关的。
原文: 滚动查看最新的,这是原来的post
数据 table 似乎只在直接导航到我在 http://server.com:9001 的 Django Web 应用程序时才有效,即使我已将所有 HTTP 流量代理到 9001。
从 http://server.com:9001/stores 查看时的屏幕截图
从 http://server.com/stores 查看时的屏幕截图
数据table只是简单地拒绝工作。更奇怪的是我在 /servers 有另一个数据 table 做同样的事情,但在 /closed-stores 有一个相同的 table 始终如一地工作(我已经连续刷新了几十次,试图让它崩溃,但它不会)。
每个 table 的 JS 都是简单的 $('#table-id').Datatable();
但我会忽略它,因为它显然可以工作,所以我相信它是我的 Nginx.conf 也许吧,或者与 Django 有关?
我还会注意到,在所有情况下,控制台中都出现 0 个错误。
Nginx.conf
server {
listen 80 default_server;
#listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
proxy_pass http://127.0.0.1:9001;
}
location /static {
autoindex on;
alias /home/usr/applications/it-database/static/;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
值得注意的是,这些 table 在我的 Windows Server 2016 开发服务器上运行了将近 2 个月没有出现任何问题,但是当迁移到 CentOS 时,这种情况开始出现。我只包括这个,因为我完全不知道问题可能是什么。
更新 1: 经过一番挖掘后,我发现问题是出于某种原因,我的 context 数据以某种方式被切断了。如果我指定端口号,我得到所有完整的数据,因此table可以转换为数据table,但当我不指定端口号时,数据将被截断店铺386(时多时少,一直在这个区)
我可以看到在某些版本的 Chrome 中,访问 /stores/
端点会出现 net::ERR_CONTENT_LENGTH_MISMATCH
错误。许多人说,对于以前的版本,这是由于中间件订单引起的,但此后已得到解决。
我的中间件:
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
/商店/视图:
@login_required
def stores(request):
stores = Store.objects.exclude(street_address__contains="closed").all()
context = {
'stores':stores,
}
return render(request, 'all_stores.html', context)
商店模板:
{% extends 'base.html' %}
{% block title %} All Stores - Stores Database {% endblock %}
{% block body %}
<br>
<div class="flex_container">
<h2>Store Database</h2>
<div class="table_header" style="float: left; position: relative;">
<br>
<h4>All Locations</h4>
</div>
<table id="store-table" class="table-striped table-hover">
<thead class="thead-light">
<tr>
<th>Store #</th>
<th>Name</th>
<th>Phone</th>
<th>City</th>
<th>State</th>
<th>Zip Code</th>
<th>Circuit</th>
</tr>
</thead>
<tbody>
{% for store in stores %}
<tr id="table-row">
<td><a href="/stores/{{ store.pk }}">{{ store.store_number }}</a></td>
<td><a href="/stores/{{ store.pk }}">{{ store.name }}</a></td>
<td>{{ store.phone }}</td>
<td>{{ store.city }}</td>
<td>{{ store.state }}</td>
<td>{{ store.postal }}</td>
<td>
{% for circuit in store.circuit_set.all %}
<p>{{ circuit.circuit_id }}</p>
{% endfor %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
<script>
$(document).ready(function () {
$('#store-table').DataTable();
});
</script>
{% endblock %}
这里的问题不一定与 Django 相关,但更多的是 Nginx 如何通过交付静态内容来处理代理。当你为静态文件设置一个 proxy_pass 时,你需要验证你的 nginx 用户是否可以访问 /lib/nginx/proxy_tmp
。您的用户可能还需要访问其他重要目录,因此我只是授予了整个 /lib/nginx
目录的所有权。
它在指定端口时传送的原因是因为我直接访问我的 Gunicorn/Django 应用程序,而不是通过 Nginx 代理,所以这个代理目录在那种情况下是不相关的。