How to arrange the settings.STATIC_ROOT to point towards the correct path?

Submitted 3 years, 6 months ago
Ticket #236
Views 299
Language/Framework Django
Priority Medium
Status Closed

I am trying to add CSS styling to my html email to be sent so I used `django-inlinecss 0.3.0` 

In my template I am using the following: 

{% load inlinecss %}
{% inlinecss "/css/bootstrap.css" %}
TEXT
{% endinlinecss %}


Here is the complete path of the CSS file:

C:\Users\User\Desktop\Project\static_in_env\css\bootstrap.css


I have tried the following: `{% inlinecss "static_in_env/css/bootstrap.css" %}`
After debugging I found that the reason is due to:
[Errno 2] No such file or directory: 'C:\\Users\\User\\Desktop\\static_root\\css\\bootstrap.css'
Here is the files structure:

# Static files (CSS, JavaScript, Images)

STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static_in_env')]
VENV_PATH = os.path.dirname(BASE_DIR)
STATIC_ROOT = os.path.join(VENV_PATH, 'static_root')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')


So, how should I fix this error? 

Submitted on Oct 18, 20

@ahmed can you confirm the ticket status?. is the issue resolved? - Vengat 3 years, 6 months ago

Second follow up on status of the ticket. Kindly update the status at the earliest. - Vengat 3 years, 6 months ago
add a comment

1 Answer

Verified

Below is my usual setting for handlig the static & media files. And it works all the time.

in settings.py file , I have assigned the static & media files like this

STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
 
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

And in project urls.py we need to enable if DEBUG=True,

if settings.DEBUG:
 
    urlpatterns += static(settings.MEDIA_URL,
                          document_root=settings.MEDIA_ROOT)

 Now in our html template, just load static files using below format,

{% load static %}

This should resolve all static related file issue. May be try this and let me know if doesnt work.

Submitted 3 years, 6 months ago


Latest Blogs