Static files on Django

Asked

Viewed 2,562 times

5

Whoa, guys, I’m having trouble uploading static files.

inserir a descrição da imagem aqui

Static folder is in the core application, also tested with it at the root of the project and also did not take

I made a test index file:

{% load static %}

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

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

Give 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: https://docs.djangoproject.com/pt-br/1.11/howto/static-files/ , but I think I’ve done something wrong

2 answers

4


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

py Settings.

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 named 'Static' at the root of your project, i.e.: where the file Manage.py is.

In your particular case, I’m not sure why you have another folder inside statics called Assets. Maybe you want to create a 'media' folder' within of Static ? I don’t know. Anyway try to remove the Assets folder and leave the static files inside the Static folder only:

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

And upload the files:

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

I hope I helped. Hugs

1

Django searches by default (provided you have the middler Django.contrib.staticfiles in your Settings) in the Static folder of each application and when you run the collectstatic it copies everything to the folder set in the STATIC_ROOT constant. Once you put the static files into core/Static/Assets

Try to do:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.