简体   繁体   中英

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. It's served with Nginx and Gunicorn. I've ran the collectstatic command and my files seem to have been copied correctly.

If somebody could shed some light into why I'm not seeing my formatting rendered in the HTML, I would very much appreciate it.

Thanks!

EDIT: Here is my nginx.conf file.

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.

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' %}

There were also other static links that I overlooked and neglected to give the proper template tag.

Thanks anyway!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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