Bootstrap未设置为我的Django应用。在Google控制台中,无法加载资源:服务器响应状态为404(未找到)bootflat.min.css错误。我在settings.py中写道

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
DEBUG =True

STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(BASE_DIR, "static/")

STATICFILES_DIRS = [os.path.join(BASE_DIR,'bootflat.github.io'), ]

在PythonServer_nginx.conf中
server {
    # the port your site will be served on
    listen      8000;
    # the domain name it will serve for
    server_name MyServerIPAdress; # substitute your machine's IP address or FQDN
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    location /static {
        alias /home/ubuntu/PythonServer/PythonServer/accounts/static; # your Django project's static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include     /home/ubuntu/PythonServer/uwsgi_params; # the uwsgi_params file you installed
    }
}

我不知道为什么Bootstrap没有设置为我的Django应用程序。我运行命令python manage.py collectstatic但没有错误发生。我该如何解决呢?我应该怎么写呢?

最佳答案

我假设元素在本地运行良好,仅当您使用nginx时才会出现此问题。如果是这种情况,则您在Nginx配置中为位置/static 提到的路径可能是错误的,请尝试从服务器获取静态文件夹的绝对路径,然后查看。

关于python - Bootstrap未设置为Django应用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47889459/

10-12 19:31