I'm having a lot of difficulty serving static files using runserver. I've included the configurations below, can someone help?
STATIC_URL = '/static/'
STATICFILES_DIR = (
os.path.join(BASE_DIR, 'static'),
)
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
Here is the top of my base.html file:
<!DOCTYPE html>
{% load static %}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="{% static 'css/style.css' %}">
<link href='https://fonts.googleapis.com/css?family=Satisfy' rel='stylesheet' type='text/css'>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
What I have done so far:
I have already issued the 'python manage.py collectstatic' command, and only 'admin' static files where placed in the /staticfiles directory. When running the command 'python manage.py findstatic css/style.css --verbosity 3' I get the following results:
C:\\Users\\john.doe\\Desktop\\sysnet>python manage.py findstatic css/style.css --verbosity 3 No matching file found for 'css/style.css'.
Looking in the following locations:
C:\\Python27\\lib\\site-packages\\django\\contrib\\admin\\staticC:\\Users\\john.doe\\Desktop\\sysnet>
Why is it searching Python27\\lib\\site-packages\\django\\contrib\\admin\\static ? I'm guessing this is is why the collectstatic command did not place files from /static in the /staticfiles?
I have included the directory structure below (minus the files), can anybody help?
sysnet
├───.idea
├───chef
│ ├───migrations
│ └───templates
├───static
│ ├───css
│ ├───img
│ └───js
├───staticfiles
│ └───admin
│ ├───css
│ ├───fonts
│ ├───img
│ │ └───gis
│ └───js
│ ├───admin
│ └───vendor
│ ├───jquery
│ └───xregexp
└───sysnet
My style.css is in /static/css, and it should work. The console output always shows 404 not found.
[29/Nov/2017 14:42:34] "GET / HTTP/1.1" 200 3588
[29/Nov/2017 14:42:34] "GET /static/css/style.css HTTP/1.1" 404 1652
I should note that everything works fine except for the static files.
设置名称是STATICFILES_DIRS
(复数)。
Your STATICFILES_DIR is a tuple, it should be a list. You have it enclosed in parentheses whereas it should be this:
STATICFILES_DIR = [os.path.join(BASE_DIR, 'static'),]
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.