2π
For the given directory structure, You can put your static files on same level as of the directory with file, mr_doorbeen/settings.py
mrdoorbeen
manage.py
mr_doorbeen
setting.py
mrdoorbeen
migrations
templates
index.html
profile
profile.html
static/
You can set the static files to the said location as follows.
# Static files configurations.
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
0π
The problem is with your settings file where you need to define STATIC_URL
. Just follow the description in Djangoβs documentation.
- [Answered ]-Highcharts using Django-Chartit. Chart lines not displayed without window resize, or Inspect Element
- [Answered ]-How to send message from django server to a nodejs server and receive the reply?
0π
I had this same problem and solved it by adding to my settings file the import of os from pathlib and the STATICFILES_DIRS line provided in one of the other responses:
from pathlib import Path, os
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATIC_URL was already properly specified to β/static/β. I couldnt solve the problem with just the STATICFILES line until I realized os is a function in pathlib that needed to be imported first.
- [Answered ]-Django: send_mail not working [only for production]
- [Answered ]-Newbie β Django Project with Multiple Apps β Unable to render Views
- [Answered ]-Django β how to query user profile based on User model having OneToOneField
- [Answered ]-Get null or empty query set in django
- [Answered ]-How to deal with virtual index in a database table in Django + PostgreSQL
0π
Also, in addition to importing os and adding the line just mentioned, copying the image files under static directly from within a folder that was under static (named after the app) was key to making it work. I kept the files in the folder under static too so there was redundancy.
After I did that, it worked, and then I could then delete the image files under static directly (not touching those within the folder under static) and it still worked. Somehow, copying them directly under static "taught" Django to access the files within the folder under static, which I dont understand, but it worked.
- [Answered ]-Empty Chatterbot Conversation table in Django Admin
- [Answered ]-Putting a click event for a dialogue box with Django Tables2
- [Answered ]-Django is not displaying the image via /media/