0

I'm new in Django and get problem. I have:

STATIC_URL = '/static/'
STATIC_ROOT = '/static/'

at my settings.py, have Project/mainapp/static folder and css/header.css inside that folder. Also i have

{% load staticfiles %}
<link rel="stylesheet" href="{% static 'css/header.css' %}" type="text/css">

at my header html. Browser tries localhost/static/css/header.css but find nothing there. What am i doing wrong? Thanks!

3
  • Did you run python manage.py collectstatic? Commented Dec 27, 2017 at 18:06
  • Maybe you need to include app port number in url like: localhost:8080/static/... Commented Dec 27, 2017 at 18:06
  • does not help guyz. Already tried collectstatic, it makes a directory admin inside static, add admin files and this is it. Anyway i run deafalt server and it is supposed to work without collectstatic. Making STATIC_URL = 'localhost:8000/static/' didnt help also. Commented Dec 27, 2017 at 18:14

1 Answer 1

1

Define STATICFILES_DIRS in your settings as below:

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

BASE_DIR is global variable you can find in same settings.py which points to project's working directory. static is your folder inside root directory of your app.

And load static in template instead of staticfiles like below:

{% load static %}
Sign up to request clarification or add additional context in comments.

2 Comments

Note: this settings will only work in django if DEBUG is set to True otherwise you need to serve staticfiles with apache or nginx
have less than 15 reputation, cant upwote now, sorry. Just chosen as the answer! Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.