C
C
Cyril2014-04-27 16:55:17
Django
Cyril, 2014-04-27 16:55:17

After git push media files on the server are overwritten. How to fix?

Good day to all!
I created an account on the OpenShift PaaS service, merged the site skeleton from there via git clone . Then he developed and uploaded changes to the server, but for some reason he ignored one problem, which now, already before the release, slows down all the work.
As expected, media files are separated from static files and are located at wsgi/media/web_site. Let's say that several files have been uploaded from the admin panel, for example, photos that will be displayed on the pages of the site. All of them will correctly rely on the wsgi/media/web_site folder on the server and will be taken from there when rendering pages. But of course, these photos are not in the folder of the same name on the local machine and they do not merge through git pull . Writes, Everything is up-to-date.
If I make changes to the code, commit and do a git push , then all the photos uploaded from the admin panel will be deleted, files from the local machine will be uploaded to the wsgi/media/web_site folder. Adding the wsgi/media line to the .gitignore file and deleting the git rm wsgi/media --cached from the git index did no good, new images from the local machine are not sent to the server, but the media folder on the server is simply deleted.
How to make it so that when pushing changes in the code, the uploaded media files on the server are not touched? or at least merge them to the local machine via git pull ?
Development with Django 1.6 and Python3

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Cyril, 2014-04-27
@Skycker

It wasn't about .gitignore, and it wasn't about git at all. The problem was a misunderstanding of the application deployment mechanism on OpenShift. Every time the git push command is executed, the service cleans up the repository folder and redeploys everything. As I understand it, for Heroku, this is also true. But there is an app-root/data folder, which is not deleted during deployment, and there you need to add media files that are loaded through the admin panel or by application users.
To avoid losing files, I corrected settings.py in this way:

# Media files
if ON_OPENSHIFT:
    MEDIA_ROOT = os.path.join(os.environ['OPENSHIFT_DATA_DIR'], 'media')
    MEDIA_URL = '/media/'
else:
    MEDIA_ROOT = os.path.join(BASE_DIR, '..', 'media')
    MEDIA_URL = '/media/'

The path to app-root/data is just contained in the OPENSHIFT_DATA_DIR system variable

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question