简体   繁体   中英

Django, trouble with static files

I'm having a lot of trouble getting all my static files to serve up. In my settings.py , I have:

STATIC_URL = '/static/'

I'm using Django 1.6, and according to the official documentation https://docs.djangoproject.com/en/dev/howto/static-files/

Since I have debug=True , this should suffice.

Then in my templates:

<link type="text/javascript" href="{% static 'jquery-1.11.1.js' %}" />
<link type="text/javascript" href="{% static 'jquery-1.11.1.min.js' %}" />
<link rel="stylesheet" type="text/css" href="{% static 'bootstrap.min.css' %}" />
<link rel="stylesheet" type="text/css" href="{% static 'jumbotron.css' %}" />
<link rel="stylesheet" type="text/css" href="{% static 'custom.css' %}" />
<link rel="stylesheet" type="text/css" href="{% static 'simple-sidebar.css' %}" />

All the CSS works fine. When I load my page, looking in Chrome's developer tools, they're coming from /static , and I have all these files stored in the same dir. But the .js files are not loading at all. They work fine if I link to the CDN.

As I said in the comments, with <script> tags, they shouldn't be self-closing so

<script type="text/javascript" src="{% static 'jquery-1.11.1.min.js' %}"></script>

note the <script ...></script> instead of <script .../>

This is probably why your subsequent link tags aren't being processed properly

What is link in

<link type="text/javascript" href="{% static 'jquery-1.11.1.min.js' %}" />

It should be

<script type="text/javascript" src="{% static 'jquery-1.11.1.min.js' %}"></script>

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