I'm getting server errors because django can't find one of my static files even though I can see it in the folder:
ValueError: Missing staticfiles manifest entry for 'staticfiles\assets\img\icons\theme\communication\adress-book-2.svg'
I see the file sitting in this folder right here in both static and staticfiles:
static\assets\img\icons\theme\communication\
file path in template:
{% load static %}
<img src="{% static 'assets\img\icons\theme\communication\adress-book-2.svg' %}" alt="Confirmation Icon" class="icon bg-primary" data-inject-svg="data-inject-svg">
Running collectstatic doesn't have any effect. Any ideas?
Thanks!
EDIT: Forgot to add settings.py static settings:
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
# Extra places for collectstatic to find static files.
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
DEBUG_PROPAGATE_EXCEPTIONS = True
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage'
First you should remove the lines that say :
# Extra places for collectstatic to find static files.
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
And then you can keep the first 2 lines:
STATIC_ROOT = os.path.join(BASE_DIR, 'Folder') #either put static or staticfiles and then remove the other folder
STATIC_URL = '/static/'
Related
I hav gone through my settings.py file to look at my static file setting
STATIC_ROOT = os.path.join(BASE_DIR,'static')
STATIC_URL = '/static/'
STATIC_DIR = os.path.join(BASE_DIR, 'static')
STATIC_ROOT = os.path.join(BASE_DIR,'static')
MEDIA_DIR = os.path.join(BASE_DIR, 'media')
but all my static files are nt showing when the page loads.
Please what could be going on
The static files where formerly working I do not know what i did that altered everything and I have gone through my settings file but found nothing wrong and the files are intact, it has not been changed
just remember to write at the top of the page
{% load static %}
There are are more than one static_root, possibly remove the static_root it looks same thing to static_dir
I am trying to load a page as PDF. actually it loaded successfully - without any style or even the images. So I installed django-inlinecss and added it in installed_apps in settings.py and loaded it in template and called it as I was told. but it returns an error
You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path.
and points at:
1 {% load inlinecss %}
2 {% load static %}
3 {% inlinecss "css/style.css" %} <---
I don't have any idea how to fix it. Hope someone could help me in this
as the error say you have to specify the path of your static and media files in settings
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static")
MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), "media")
actually it worked when I set directory for STATIC_ROOT. but there is one thing to be noticed that you have to set another directory for that. Which means STATIC_URL and others like STATIC_FILE_ROOT, STATICFILES_DIRS shouldn't be the same as STATIC_ROOT
eg:
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
STATIC_URL = '/static/'
STATIC_FILE_ROOT = os.path.join(BASE_DIR, "static")
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
STATIC_ROOT = os.path.join(BASE_DIR, "static/assets")
sorry if that's not what you are looking for.
I'm working on a Django project and I can't see my static folder, I'm also having a problem displaying images.
And when I inspect the image div in the src it's written unknown, Here's how I display the image from the admin
``<img class="rounded-circle account-profile" src="{{ user.Profile.profile_photo.url }}" alt="profile">``
User is the current user, the profile and then the name of the column.
My folder structure is route-folder( project-folder, media-folder and app-folder )
My static settings
```STATIC_URL = '/static/'
SITE_ROOT = os.path.dirname(os.path.realpath(__file__))
STATICFILES_DIRS = [
os.path.join(SITE_ROOT, "static/"),
]```
The Url:
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
I think you are trying to retrieve a media image not a static one. I recomend using Whitenoise package to serve static files.
Follow instruction in this tutorial: http://whitenoise.evans.io/en/stable/django.html
Check you have all this setup:
# Settings
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)
In the templates, you should remember to add the {% load static %} to grant access to the actual files.
For some reason that I can not figure out. Only some of my static files are not loading. They used to but not anymore.
The ones loaded with django-bower work fine, any others don't.
Is it possible django-bower broke it or have I missed something.
settings.py
STATIC_URL = '/static/'
STATICFILES_FINDERS = ('djangobower.finders.BowerFinder',)
STATIC_ROOT = os.path.join(BASE_DIR, '..', 'static')
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'))
BOWER_COMPONENTS_ROOT = os.path.join(BASE_DIR, 'components')
BOWER_INSTALLED_APPS = (
'jquery#1.9',
'knockout#3.3.0',
'knockout-mapping#2.0',
'bootstrap',
)
template:
{% load staticfiles %}
<link href="{% static 'css/styles.css' %}" rel="stylesheet">
project structure:
- project
- apps
- src
- static
- css
- styles.css
- media
You've replaced all staticfiles finders with only one, BowerFinder. This is no suprise that static files will be collected only from bower.
By default STATICFILES_FINDERS will contain:
(
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
)
If you still want to use that staticfiles finders, you must set them together with your BowerFinder.
Try as:
<link href="{{ STATIC_URL }}css/styles.css">
I've a project, actually is the test from appfog (https://github.com/appfog/af-python-django) that run smoothly in localhost. But it does not work, at least static files are not recognized once deployed on appfog.
I've changed just the location of tempaltes.
This is the test page http://st-test.eu01.aws.af.cm/ . as well, also the admin pages are without css http://st-test.eu01.aws.af.cm/admin/
this is my configuration (setting.py)
STATIC_ROOT = ''
STATIC_URL = '/static/'
STATICFILES_DIRS = (
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
i also tried with
STATIC_ROOT = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'static')
but nothing changes.
i've tried with doing collectstatic locally and then update the files on the repository, but nothing works.
does anyone of you know how to make it working?
btw, in the template i use {% load staticfiles %} and {% static "css/style.css" %}
This works for me:
settings.py:
import os
ROOT_PATH = os.path.dirname(__file__)
STATIC_ROOT = os.path.join(ROOT_PATH, 'static')
STATIC_URL = '/static/'
urls.py:
(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT}),