DJANGO Static Image deletion - django

I am experiencing an issue with images saved in the static/images directory in Django. My website was rendering images appropriately, by referencing the name of the image e.g., Image_1. However, once I've tried to delete this image and include a new one in the static/images directory with the same name, Image_1, the website keeps rendering the old image. New images added in the same directory with new names are rendered without issues.
Since then I have specified all STATIC_ROOT, MEDIA and MEDIA_ROOT routes in settings.py, I have run manage.py collectstatic and I have checked the images stored in these directories. The "old" version of Image_1 is not there anymore, but the new one is, and the website still renders the "old" version of it.
Does anybody have an explanation for this, and how to fix it?
Thanks in advance!

Try reset your browser cache "ctrl + f5"

The browser has cached the old image in the PC of browser side .
Close the Page and clear the cache files of the browser,then try again.

Related

Django Admin Styling corrupted

I recently made some changes to my django site, one big one being upgrading from Django 2.2 to 3.1. Now my admin site styling is all messed up. I can't figure out what went wrong or how to fix. Any pointers would be appreciated!
See image of what it looks like after update....
The main home page for admin looks fine, but when I click on one of the models to view, the formatted is definitely not correct.
Also, some not all, of my images on the site are saying 404 not found...
It looks like your browser is caching the CSS / JS from the old version, you can clear your cache and reload. In chrome use ctrl + shift + r to reload.
I was facing the same problem, First I thought it was a Cache issue but it wasn't.
I checked the page source and found a css file being applied to the page which wasn't even present on my drive.
In my case the file was:
static/admin/css/nav_sidebar.css
So I created new file in static/admin/css named nav_sidebar.css,
then copy pasted the code which I got from page source and
added "display:none;" in the #nav-sidebar section(line:34) and [dir="rtl"] #nav-sidebar section(line:45 in my case).
You can find the Original code here by using Google Chrome's inspect tool.
Where to find the code
I had the same issue after bumping django from v3.0 to v3.1. I run python manage.py collectstatic to update css which solved my issue
I was experiencing the same styling as the OP's screenshots.
I had upgraded incrementally from 2.2 -> 3.0 -> 3.1 -> 3.2. I only experienced the styling issues in 3.2
The issue was that there were legacy admin styles committed to the repo in the static folder. To resolve, all I did was delete the committed admin styles, and Django then appeared to use its own styling
I was upgrading from 3.0 to 3.2 and I tried a couple of the answers here without luck. At the end, the following procedure solved it for me:
manually delete the content of the directory STATIC_ROOT (see in settings.py what you named the folder)
run the command python manage.py collectstatic This will repopulate the directory with the newst files
hard refresh your page (ctrl + F5)
I think the other answers here are necessary, but I'll add one more: You might have to bust caches in your server itself. In our example, nginx was configured to provide really long caches to our static files, so we just had to reset it to make changes come through.
Ok maybe I am late to the party but it may help others,
What works for me is:
Set STATIC_ROOT in settings.py (I guess it should be already there as project is old one)
Comment STATIC_DIR in STATICFILES_DIRS list (otherwise it will give error) and run python manage.py collectstatic
Clear browser cache.

Image URL doesn't retrieve image

I load an image to my server side in django-admin with ImageField.
My server is deployed to Heroku.
I browse a .png image and search his path, I received it properly.
After couple of minutes, the server doesn't retrieve the image.
In the server logs, I get status 200 or 301, in both cases I don't get the image.
Anyone have any idea to help me find a way to fix this situation?
EDIT:
I find out that it occur because of an IOError after reading the image file.
It is happening with two files from a total of three (the third one is .png and is showing properly and his size is a bit smaller) I think it means, it won't always happend and there is no problem with the path because of it.
EDIT 2:
The way I thought i solved it, didn't worked.
any other idea?
As Fian mentioned in the comments:
There is high chance that there is something wrong with paths. Please
add your MEDIA_URL, MEDIA_ROOT, ImageField code from model and
serializer and image-url that is passed by your server to browser.
What I believe was the problem is, Heroku auto collectstatic to my staticfiles directory.
When I uploaded an image, I had no MEDIA_ROOT and MEDIA_URL settings.
Because of this, every image I uploaded was saved in the BASE_ROOT temporary and I had access to him.
Once in a while Heroku collectstatic my files to my static directory and I lost my connection to those files because of it. I was searching for those files in my BASE_DIR and they have been moved to the staticfiles directory.

Django app copied to new location is still accessing old files, because it is using the wrong settings.py

Django version 1.4, using Supervisor, NGINX, gunicorn, and postgresql 8.4. The project where an app was located has been moved to a different server which also has the domain now. I had another project hosted on this same server, and I want to move my app over to that project with all database data intact.
I moved the app files (models.py, views.py, etc.) to a folder in the destination project, moved the templates to corresponding folders, added the app to the destination project's settings.py, and ran manage.py syncdb. Using PGAdmin's backup and restore I moved all of the data over. After updating some relative references in the python files I was able to access all of the database data (which seems entirely intact) in the Django admin site.
Now the problem: the new urls seem to work fine, but it is using the old project's .py files and all templates. I even commented out the app in the settings files of both new and old projects and all it did was hide the admin site from me.
To identify the problem I inserted a typo into the old project views.py, and got it to throw a traceback, which let me see that it was using the old project's settings.py instead of the new one. How do I make the app switch to the new project settings.py? How is it even finding the old one?
I realize after the fact that this question probably belongs on Server Fault instead of Stackoverflow. I did figure this out, though, and posted the answer on SF:
https://serverfault.com/a/722742/311615

Is there a specific solution for file permission issues?

I am doing a website(Joomla) and I am using admiror gallery. Everything is working fine while I was working in the localhost but now that I migrated it to a live server, I am having problems in uploading images in the gallery.
The first is when I create a new folder to contain my new images. When I create it and try to upload a zip file, it's taking forever to load only to find out that it's not even uploading at all. When I looked into it, the reason is when a new folder is created, the permission is 755 by default, thus, making changes on the folder is not allowed. I need to change the file permission to 777 and now I am able to upload my images but there is another problem that occurs. The thumbnails in the backend are showing broken images. This is because the 'thumbs' directory in home/administrator/components/com_admirorgallery/assets/thumbs/ is again set to 755. I tried to change it to 777 and reupload the images again. The images gets uploaded but the problem with the thumbnails is still there. I checked again the folder and the permission is reverted back to 755.
Is there something I can do with this? Any suggestion is appreciated. Thanks in advance.
You should check the files and folder owner, not only permission.
PHP user (Joomla) is the creator of thumb folder, thus it should be able to create files in that directory. Also, it is not safe to have 777 on live site.
Shambhala made a suggestion that should help. Also you should use AkeebaBackup when migrating from local to live server, I never had problems with it.

Images no longer displaying after migrating a django cms

The problem occurs when the site admin uploads images, this works all fine and dandy so it's on a permissions issue on the images directory. But once the image is uploaded, the thumbnail preview no longer works (was fine on the other server) nor does the direct link to the image ( /images/somerandom.jpg).
I have checked server side and the images does in fact exist in the images directory and the thumbnail for previewing is also being created.
I have checked a bunch of permissions and setting the entire directory to both chmod 664 and 666 none of which makes any difference. Ownership on the entire images directory and it's contents have been set to apache.apache too, to no avail.
Any suggestions or help would b greatly appreciated.