21đź‘Ť
Have you defined your static files directory in settings.py
?
I’m guessing you have 'django.contrib.staticfiles',
in your installed apps.
If you haven’t defined your static files dir, you could by doing something like this:
import os.path
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
STATICFILES_DIRS = (
os.path.join(PROJECT_ROOT, 'static'),
)
3đź‘Ť
This is the working solution for static/media/template access in django for windows,
settings.py
import os.path
STATIC_ROOT = ''
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join('static'),
)
- Django and Dropzone.js
- Django and Azure SQL key error 'deferrable' when start migrate command
- Django Rest Framework – Getting a model instance after serialization
- How to add 'collapse' to a Django StackedInline
- Making a text input field look disabled, but act readonly
3đź‘Ť
My problem was solved by adding “STATICFILES_DIRS” in settings.py file
STATIC_URL = '/static/'
STATICFILES_DIRS = ( os.path.join('static'), )
2đź‘Ť
Check if STATICFILES_FINDERS
is defined in your settings.py
https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_FINDERS
The default value of STATICFILES_FINDERS
is good enough but you have 2 choices :
-
you need to have the static file inside an app and having this app in your
INSTALLED_APPS
-
or you need to define
STATICFILES_DIRS
with your path to the static files if expect the behavior being the one ofdjango.contrib.staticfiles.finders.FileSystemFinder
- Django redirect to root from a view
- Django Admin + FORCE_SCRIPT_NAME + Login redirects incorrectly
- Cookie not being set on angular client
- Heroku Upload – Could not find a version that satisfies the requirement anaconda-client==1.4.0
1đź‘Ť
I thought Django did this automatically when you run the server?
Why did you think that? If you’ve followed the official documentation, you won’t have found that. Read what you have to do to serve them in development here.
There’s another problem. Your STATIC_URL
is a relative link, so browsers add it to the existing page URL. So if you’re on page /foo
, 'static/css/style.css'
evaluates to /foo/static/css/style.css'
.
Make sure it either starts with /
– ie /static/
– or is a full URL, ie http://myserver.com/static/
.
- Parse HTTP_USER_AGENT string in django.
- Django is very slow on my machine
- What is Serializers to_internal_value method used for in Django
0đź‘Ť
I encountered this problem too. And I solved the problem by revising the href like this:
<html>
<link rel="stylesheet" href="{{STATIC_URL}}css/bootstrap.css" type="text/css">
<link rel="stylesheet" href="{{STATIC_URL}}css/style.css" type="text/css">
</html>
- Model inherited from AbstractUser doesn't hash password field
- Django annotate() error AttributeError: 'CharField' object has no attribute 'resolve_expression'
0đź‘Ť
Make sure that you have the static folder set up in the right place, that is if it is in the app folder, then you can get further clarification from this helpful resource1.
- Experiences of creating Social Network site in Django
- Django ManagementForm data is missing or has been tampered with
- DRF – How to handle exception on serializer create()?
- Django object is not iterable using serializers.serialize