Static files in Django

2

Oops, I can not load static files.

Thestaticfolderisinthecoreapplication,Ialsotesteditwiththerootprojectandalsodidnotgetit

Imadeatestindexfile:

{%loadstatic%}{%static"assets/css/bootstrap.css"%}

<link href="{% static "assets/css/bootstrap.css"%}" rel="stylesheet">

Gives the following error in the browser console:

GET http://127.0.0.1:8000/ [HTTP/1.0 200 OK 3 ms]
GET http://127.0.0.1:8000/static/assets/css/bootstrap.css [HTTP/1.0 404 Not Found 7 ms]
GET http://127.0.0.1:8000/static/assets/css/bootstrap.css [HTTP/1.0 404 Not Found 0 ms]

I followed the django documentation: link , but I think I did something wrong

    
asked by anonymous 11.10.2017 / 21:01

2 answers

0

The first thing to do is to check the PATH of your static files, ie where you are sending them.

settings.py

STATIC_URL = '/static/'

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static'),
] 

This would be a very common example in a development environment. Your statistical files are served in a folder called 'static' at the root of your project, ie where the manage.py file is.

In your particular case, I'm not quite sure why you have one more folder inside 'statics' called 'assets'. Maybe you want to create a 'media' folder in the static? Do not know. Anyway try to remove the assets folder and leave the static files inside the static folder only:

-static
----css
----fonts
----img
----js

Upload files:

{% load static %}
    <link rel="stylesheet" href="{% static 'css/bootstrap.css' %}"> #exemplo tirado de um projeto pessoal em funcionamento. 

I hope I have helped. Hugs

    
11.10.2017 / 21:35
0

Django looks for default (as long as you have the django.contrib.staticfiles middler in your settings) in the static folder of each application and when you run collectstatic it copies everything to the folder set in the STATIC_ROOT constant. Once you have placed the static files in core / static / assets

Try to:

    
19.10.2017 / 16:03