我已经重新配置了nginx,但我无法使用以下配置重新启动它:
CONF:
server {
listen 80;
server_name www.example.com;
return 301 $scheme://example.com$request_uri;
}
server {
listen 80;
server_name example.com;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location /robots.txt {
alias /path/to/robots.txt;
access_log off;
log_not_found off;
}
location = /favicon.ico { access_log off; log_not_found off; }
location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 30;
proxy_read_timeout 30;
proxy_pass http://127.0.0.1:8000;
}
location /static {
expires 1M;
alias /path/to/staticfiles;
}
}
Run Code Online (Sandbox Code Playgroud)
在运行sudo nginx -c …
我想在django的list_display属性中显示相关对象的数量.例如,我们有一个类别字段,我们想要显示在此类别中发布了多少博客帖子
到目前为止我试过这个:
admin.py:
from .models import Category
class CategoryAdmin(admin.ModelAdmin):
def category_post_count(self, obj):
return obj.post_set.count
category_post_count.short_description = "Posts Count"
list_display = ['category', 'category_post_count']
Run Code Online (Sandbox Code Playgroud)
models.py:
class Category(models.Model):
category = models.CharField(max_length=25)
class Post(models.Model):
category = models.ForeignKey(Category, null=True, blank=False)
Run Code Online (Sandbox Code Playgroud) 我正在尝试按name
每个记录的字段字符对记录进行分组,并限制每个组中的项目,这是我想出的:
desired_letters = ['a','b','c',..,'z']
some_variable = {}
for desired_letter in desired_letters:
some_variable += User.objects.all().order_by("name").filter(name__startswith=desired_letter)[:10]
Run Code Online (Sandbox Code Playgroud)
我在for循环中运行此查询并更改desired_letter
为我想要的字母,有没有其他方法来优化此解决方案并使其成为单个查询而不是for循环?
我正在尝试在C#中编写一段代码来查找整数的数字,这段代码适用于所有数字(负数和正数),但我有10,100,1000等问题,它显示比数字的实际位数少一个数字.像10表示1和100表示2 ..
long i = 0;
double n;
Console.Write("N? ");
n = Convert.ToInt64(Console.ReadLine());
do
{
n = n / 10;
i++;
}
while(Math.Abs(n) > 1);
Console.WriteLine(i);
Run Code Online (Sandbox Code Playgroud) 尝试更新代码时,在我的项目目录中,由于修改了模型并在使用时python manage.py makemigrations
收到以下消息,所以我不小心删除了应用程序的migrations文件夹:
Operations to perform:
Apply all migrations: app_label
Running migrations:
No migrations to apply.
Run Code Online (Sandbox Code Playgroud)
我已经在迁移之前运行了它 python manage.py makemigrations app_label
在这段代码中,我试图将0到9之间的随机数添加到一个数组中但是当我试图在for循环中为数组分配数字时,我收到此错误:
错误1使用未分配的局部变量'x'
这是代码:
using System;
class Core
{
public static void Main()
{
Random rnd = new Random();
int[] x;
for (int i = 0; i < 4; i++)
{
x[i] = rnd.Next(1, 9);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我已经阅读了编译器错误CS0165的 MSDN描述,但它没有谈论数组.