Deploying Django - Most static files are appearing except images - python

Most of my static files on my newly deployed Django website are working (CSS), but not the images. All the images are broken links for some reason and I cannot figure out why. I am serving my static files via Amazon AWS S3.
I believe all my settings are configured correctly as the collectstatic command works (and the css styling sheets are up on the web). What could be the problem?

It's probably impossible to give an accurate assessment with the limited info on your setup. If your css files are working what folder are they sitting in on your server?
Why not have images folder in the same directory and set that directory to your MEDIA_URL in your settings.py file?
In your browser check your images full path and compare that to your CSS files, where are they pointing, do you have a directory on your server where they are supposed to be? are you receiving an access denied if you try to directly put in that image url into your browser?

Related

my css, js and imgs files are not comming in static folder

After running the following command for the Django project:
python manage.py collectstatic
Some other CSS files are generated, but the following CSS files "that exist in my template folder" are not coming into a static generated folder.
When I manually copy-paste these files after the command then it works on local to load, but on production upon deployment to Heroku, it again runs collecstatic command which overwrites those files and then it doesn't load.
I also have disabled collect static upon deploying the project to Heroku to prevent overwriting then again it does not load CSS files from the static folder.
Please, does anyone, know how I could deal with it? thanks in advance
You should keep static files under appname/static folder not in appname/templates. Collectstatic copy files from appname/static only

Css file not loading on Python Anywhere

I have recently begun making a Django project on PythonAnyhwere.
I have followed the entire tutorial provided by Django for including static files on the project. I have observed the programs work fine on a site with http, but does not work on a site with https.
What could be the reasons and how can I overcome this problem?
Edit : The site is working now, apparently, but I would still like an explanation as to why it WAS working differently, if anyone can provide.
to load your CSS files (or totally static files), you need to follow the steps below:
1- inside settings.py
STATIC_URL = '/static/'
STATIC_ROOT=os.path.join(BASE_DIR,'static')
MEDIA_ROOT=os.path.join(BASE_DIR,'media')
MEDIA_URL='/media/'
2-collect static files using bash console
python manage.py collectstatic
3-you need to enter the Static files directory inside the web tab
check the image below
static files python anywhere
4- reload your web app

static images not served after deployment to heroku

I'm working on a small web application built with python and plotly-dash. Everything worked fine locally and so I deployed the code to Heroku. This also worked fine except for 2 out of 17 static images in the assets folder that won't get served after deployment. The error message is:
Failed to load resource: the server responded with a status of 404 (NOT FOUND)
The initial settings for plotly-dash were set to 'serve assets locally'. So I tried to serve them from an S3 bucket with the same result. These two images can't be found on the server.
One more piece of information. I saw that the file extension for both of these files was '.JPG' instead of '.jpg' for all the other files that are showed correctly. I saved them under XY.jpg but this didn't solve the problem either.
Any ideas what might be the problem here? I honestly run out of ideas. The code can be found here and the website is hosted here Click on 'Analyze' and 'Show me more details' to get to the problematic page.
I appreciate every input. Thanks inadvance.
I finally found the solution. Even though I changed the file extensions from 'JPG' to 'jpg' locally this change didn't make it to GitHub. I ended up converting the files to PNG format, adding and referencing them in the code and they finally showed up after deployment.

Access Denied - CloudFront + Django Compressor

Just started using django compressor along with my AWS/Cloudfront setup on Heroku.
Having an issue on my local machine where the compressed CSS and JS files are not loading for the page and when i view the source (CSS Example)
It is showing as “Access Denied”
https://d3dycr1vdfv0cd.cloudfront.net/static/CACHE/css/50c1fe094e5d.css
I thought this might be a permissions issue on my S3 bucket and clicked on “Make Public” on my CSS folder in S3. But still no luck.
any ideas?

js and css files are not read in a DJANGO project

I am reformulating a previous question because I think it was formulated as a Python problem but it is a Django one.
I am installing a project from github called publicmarkup:
The main page displays on the browser but no media (neither js files, nor css files) are read loaded. There is a module called mediasync that seems to be necessary to display correctly the css and the js files of the templates.
I think this a configuration problem. Here's the link settings.py file, Here it could be find the root path of the media folder.
And here's the doc for the mediasync modulet explains how to configure static_url
But I didn't understand anything since I am a newbie to djnago
In Django you have to set up your own workstation serve static files, in both dev and live modes.
You can read about it here.
This explains how to serve static files in your dev environment.
In live mode you serve your static files directly via your end web server, usually either Apache or Nginx.

Categories