简体   繁体   English

无法让Django呈现Bootstrap

[英]Can't get Django to render Bootstrap

I'm a bit stumped on this one. 我对此有些困惑。 Perhaps somebody can tell me what I'm forgetting to do. 也许有人可以告诉我我忘了做什么。 Here is the structure of my project. 这是我的项目的结构。

└── django_project
├── django_project
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   ├── wsgi.py
├── joe_develops
│   ├── admin.py
│   ├── __init__.py
│   ├── models.py
│   ├── tests.py
│   ├── views.py
├── manage.py
├── static
│   ├── about.html
│   ├── admin
│   ├── contact.html
│   ├── css
│   ├── fonts
│   ├── img
│   ├── index.html
│   ├── js
│   ├── less
│   ├── LICENSE
│   ├── mail
│   ├── post.html
│   ├── README.md
│   └── startbootstrap-clean-blog-1.0.3
└── templates
    ├── base.html
    └── index.html

Bootstrap code is kept in the static folder. 引导程序代码保存在静态文件夹中。 My settings look like this. 我的设置如下所示。

STATIC_ROOT = '/home/django/django_project/static/'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
    "/home/django/django_project/static",
)

In my templates, I call static data in the following way. 在模板中,我通过以下方式调用静态数据。

{% load staticfiles %} 
...

<!-- Bootstrap Core CSS -->
<link href="{% static '/css/bootstrap.min.css' %}" rel="stylesheet">

<!-- Custom CSS -->
<link href="{% static '/css/clean-blog.min.css' %}" rel="stylesheet">

I'm operating on the Django 1.6 Digital Ocean stack. 我正在Django 1.6 Digital Ocean堆栈上进行操作。 It's served with Nginx and Gunicorn. 它与Nginx和Gunicorn一起使用。 I've ran the collectstatic command and my files seem to have been copied correctly. 我运行了collectstatic命令,并且我的文件似乎已正确复制。

If somebody could shed some light into why I'm not seeing my formatting rendered in the HTML, I would very much appreciate it. 如果有人可以弄清楚为什么我看不到HTML中呈现的格式,我将不胜感激。

Thanks! 谢谢!

EDIT: Here is my nginx.conf file. 编辑:这是我的nginx.conf文件。

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;
        gzip_disable "msie6";

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

        ##
        # nginx-naxsi config
        ##
        # Uncomment it if you installed nginx-naxsi
        ##

        #include /etc/nginx/naxsi_core.rules;

        ##
        # nginx-passenger config
        ##
        # Uncomment it if you installed nginx-passenger
        ##

        #passenger_root /usr;
        #passenger_ruby /usr/bin/ruby;

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}

For anybody who was curious, this is an error with the way I was calling my static files in my django template. 对于任何好奇的人,这是我在Django模板中调用静态文件的方式的错误。

For example in the following call the forward slashes at the beginning of the string were causing the files not to link properly. 例如,在以下调用中,字符串开头的正斜杠导致文件无法正确链接。 {% static '/css/path/file' %} should be {% static 'css/path/file' %} {%static'/ css / path / file'%}应该是{%static'css / path / file'%}

There were also other static links that I overlooked and neglected to give the proper template tag. 我还忽略了其他静态链接,并忽略了它们以提供适当的模板标记。

Thanks anyway! 不管怎么说,还是要谢谢你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM