I am new at django.
I upload images and it was working well when in development.
I use pythonanywhere for deploy my code.
The problem is I can upload image on admin but can't display unless reload the server.
I can show some code snippets you want.
I have no idea what the problem is
Also used Whitenoise to server media files. I added below the code I put to wsgi file in pythonanywhere
application = DjangoWhiteNoise(application)
application = WhiteNoise(
DjangoWhiteNoise(get_wsgi_application()),
root=settings.MEDIA_ROOT,
prefix='/media/',
)
Related
I have just deployed my first flask app, however, I have found out that it is really easy to download all the code I spent so long writing. For example, if my app was app.com, users can simply go to the website /app.py and my app.py would get automatically downloaded. Same for the passenger_wsgi.py and every other folder short of a db.
How can I disable that without compromising the integrity of my flask app?
I deployed my app to heroku: https://doggos-only.herokuapp.com/
The images on the Dog Images link work locally, but they do not work on the deployed version. The only useful error I'm getting is: cj_eOAaboi.jpg:1 Failed to load resource: the server responded with a status of 404 (Not Found)
My best guess is that it has something to do with the file path, but I'm not sure. I've tried looking around the web for a solution but have been unable to find one. Looking for any help, here is the repo: https://github.com/jpchato/doggos_only_project
I'm deploying from the deploy_branch in my repo.
That's because media files (Those files uploaded by the user) in heroku are not persistent, that means that after a certain time all the media will be erased.
I strongly suggest you to use a media CDN like cloudinary or amazon s3.
I wrote a post on how to setup a media CDN with cloudinary for free and you can access it right here
Django Tutorial: Set up Media files in Deployment for FREE
I have a Blog created with Django 3.x. When I run the project on my local server then it works fine. So, I deployed my project to heroku and here is the link bblog-shovon.herokuapp.com/. Then the project was working fine. My project git link https://git.heroku.com/bblog-shovon.gitThen I created a post and then I gave it a thumbnail and finally everything was fine. But, After sometime when i revisit the site then every image were gone. I didn't found them. And when I tried to open the image on another tab then it shows this Error message screenshot. When I am writing this question then I created a new post and after publishing this this posts image is working. But, older image is not working.
Then, How can i fix this problem? Please help me!!
Heroku flushes the filesystem to the latest commit. So you will have to use third-party plugins such as AWSBucket, etc.
With Heroku the filesystem is not persisted so you will lose media files occasionally. Use S3 or some other provider to store your user-uploaded media (also your static files if you want, otherwise use whitenoise). Django-storages makes it very easy.
I recently uploaded my Django App to the server (Digital Ocean). The functionality is okay as in my local project on my computer, but the design (css style) of the Admin Interface has changed drastically in a lot of elements of the change_list and change_form templates. I‘ve checked and made sure that the templates of my local Django and Suit files are the same as they of the server, but it is still not the same design.
Does anyone has experience with that?
In deployment server just collect your static files from static folder by running command python manage.py collectstatic which will create a staticfiles folder in your Main project app in the project directory. May be this will help. Try it out.
Currently I have react app that is consuming rest API written in python. But I want to know whether can I use React to generate template and render it from server?
Depending on what server side framework you are using, you can build a static version of your react app and serve it from your static directory. If you peak around this github repo, you'll see it does exactly that with a Django app: https://github.com/ethankulman/react-django-boiler
To create static version of your app, you'll want to go to your react directory and use the command
npm run build
You'll see a new folder in your directory named "build" and it contains all the necessary files to serve your app statically.