Django 1.8 Static Files Doesnt Work

Static file doesn't exist and html-file doesn't work properly

Do this:
settings.py:

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

urls.py:

urlpatterns = [
path('', views.news_home, name='news_home'),
path('make_vision', views.make_vision, name="make_vision"),
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

In templates:
make_vision.html:

{% extends 'main/base.html' %}
{% load static %}
{% block title %}Добавление записей{% endblock %}

{% block content %}
<div class="features">
<h1>Форма по добавлению статьи</h1>
<form method="post">
<input type="text" placeholder="Название статьи" class="form-control"><br>
<input type="text" placeholder="Анонс статьи" class="form-control"><br>
<textarea class="form-control"><br>
<input type="date" class="form-control"><br>
<button class="btn btn-success" type="submit">Добавить статью</button>
</form>
</div>
{% endblock %}

Django STATIC FILES not loading in actual Production

Actually in my Nginx server file I commented following section and it worked

location /static/ {
...
}

Django static files are broken

url:

static(settings.STATIC_URL, document_root=settings.STATIC_DIR)

settings:

STATIC_DIR = BASE_DIR / 'static'
STATIC_ROOT = BASE_DIR/"static_root"
STATIC_URL = '/static/'
STATICFILES_DIRS = [
STATIC_DIR,
]

try to use STATIC_DIR & STATIC_ROOT different name for confusion.

404 error when getting file in static, django

An Excerpt from the docs.

Your project will probably also have static assets that aren’t tied to a particular app. In addition to using a static/ directory inside your apps, you can define a list of directories (STATICFILES_DIRS) in your settings file where Django will also look for static files.

So, use list of dictionaries and also it is STATICFILES_DIRS not STATICFILES_DIR, you missed S.

Try this:

STATIC_URL = 'static/'
STATICFILES_DIRS = [
BASE_DIR / "static"
]

Or this:

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

Make sure that you have loaded the static tag using % load static %.

Django 1.8 and the ever confusing Static Files

You are missing an 's' from STATICFILES_DIRS.

Also, you shouldn't be including your BASE_DIR in that setting - that could end up serving all your python code, which would be a bad idea.

Static Files won't show with Django

I fixed this issue.

I was linking the wrong folder the entire time. Silly mistake.

Thanks everyone for your help :)



Related Topics



Leave a reply



Submit