There are user avatars which are uploaded by user and stored in /media/users. In test environment these images are showing properly, but on production with identical code we have blank field instead of image and site.com/media/users/image_name.jpg redirects to other page, i. e. cannot find image. We cannot debug production server so I want to ask what possible causes can this behavior have?
is there a possibility that you are not serving the /media files using a webserver (like nginx) and the requests go to django app which (with the DEBUG flag turned off) doesn't handle media_url ?
Related
I uploaded a few icons to the static/img/ directory in my Django project, which is based on the Django Admin interface. I have one testing server and one production server. Both are using
https://fra1.digitaloceanspaces.com to store static project files. To display specific icons, I created custom field in Django ModelAdmin:
def get_type(self, obj):
return format_html(
'<img alt="type" src="{static_url}/img/type_icons/type-{type}.png">',
static_url=settings.STATIC_URL,
type=obj.type
)
project/settings.py
When developing locally STATIC_URL = '/collected-static/'.
In development and production mode STATIC_URL = '{}/{}/static/'.format(AWS_S3_ENDPOINT_URL, AWS_STORAGE_BUCKET_NAME).
AWS_S3_ENDPOINT_URL is https://fra1.digitaloceanspaces.com.
AWS_STORAGE_BUCKET_NAME is either project-develop (testing) or project (production). These variables are configured in deployment YAML file.
Locally and in development(testing) mode images are displayed perfectly fine this way, but inside production mode images are not displayed at all. I've tried changing the location of the files and even changing the deployment configuration, but nothing seems to help getting the icons to show up in production.
/collected-static/img/type-object_type.png (example of icon img src on localhost - OK)
https://fra1.digitaloceanspaces.com/project-develop/static/img/type-object_type.png (example of icon img src on testing server - OK)
https://fra1.digitaloceanspaces.com/project/static/img/type-object_type.png (example of icon img src in production - NOT DISPLAYING)
I would like to hear your opinion on this problem I am having. I've been struggling with this for quite some time. Perhaps there is a better way to handle static files in Django Admin.
checking the permission of the static directory on a production server
if you are using a web server like Nginx to serve the static directory will be useful
[Update]
I've managed to upload a small file (but not yet a large image). ../media/filer_public/ sub-directories are being correctly created and file correctly uploaded. Need to investigate nginx configurations.
[OP]
I've logged into a new Django CMS system as superuser but cannot Add filer image or Add filer file to a page as the file upload silently fails; very briefly flashing its upload graphics but not actually uploading anything. I believe all the settings.py are correct as static artifacts are rendered correctly and Nginx has credible similar locations for both media and static directories.
I believe all file and directory permissions and ownerships are correct; i.e. that Nginx has user and / or group ownership of the Django CMS app directories and that permissions are correct.
The Postgres table filer_folder has a row for a new filer folder I created when editing a page but no corresponding directory has been created in the file system. I can add text and new text block plugins that get saved correctly.
Django CMS is running in a Docker container web which I have confirmed has rw (read/write) access to a Docker volume.
I see nothing abnormal in webs logs.
How can I find out what's (not) happening?
Simply adding client_max_body_size 10M; to the nginx configuration for the site solved the issue.
Similar issues were addressed in Stackoverflow and elsewhere:
Server Fault
Setting up Django and your web server with uWSGI and nginx
I have some models with ImageFields (that work fine on my home computer test environment). When I put the project on a server using Passenger WSGI, submitting a form in the admin containing an ImageField doesn't work.
If DEBUG is True, I get a 404 error page saying that it can't find 500.shtml (I didn't create a 500 error page). No error appears in the server console.
If DEBUG is False, I get an Apache message saying it can't find "admin/red_projects/project/add/" (the URL it was JUST at), and the server error log has a message saying that the folder admin doesn't exist in the filesystem (since it's not a directory, just a Django urlconf), or it just hangs and doesn't load the page.
I already recursively set the permissions on the media directory to 755, and that didn't do anything. Everything else works fine, including submitting admin forms without ImageFields.
Django dosn't serve media or static files when debug is False, you shoud have and alias in your configuration to serve them via the web server directly (Way faster than using django to serve them)
Read this, it will help you put it in production : Deploying static files
Edit: This is for static files, same things aply to media files
not able to view my pictures on the template
1)added avatar to installed apps
2) edited urls
3) added code in temlplates
kindly help if any other change is required?
You have probably not setup the media and static url settings in settings.py either that or you have not configured the HTTP server you are running to display images from those locations (assuming you are not using the dev server). Obviously it is hard to help with no information so perhaps providing a bit more might be useful (some code for example).
I'm running a Django app for my root public_html folder, and it's working fine. But there's a problem with one of my other apps. The problematic app is accessed through a redirect to a subdirectory (e.g. http://workingsite.com redirects to public_html, http://brokensite.com redirects to public_html/foo)
The problem is that the session expires whenever anything needs to be saved in the Django admin (either added or changed). If you try again, sometimes it works. This does not happen on my own machine when I run the Django dev server.
The timezone in both of the app settings.py files is the same, which is the same as the timezone in both of the .htaccess files.
The apps are almost identical, except the working app uses WYMEditor and the broken one uses TinyMCE as its text editor. Don't know why that would do anything to cause the problem, but I included it just in case. Also, I've made a custom CSS file for the admin backend in the broken app (again, shouldn't cause a problem).
Seems to have been a configuration issue with the company I was hosting with - it's not happening anymore.