django-media

two copies of images are stored each time I upload an image in django?

笑着哭i 提交于 2019-12-13 04:59:25
问题 when I upload an image, i see it uploaded twice in my project. The two locations are /Users/myproject/media/ and /Users/myproject/media/assets/uploaded_files/username/ . I expect the image to be uploaded only to the latter. why two copies are uploaded and how to avoid it? In settings.py: MEDIA_URL="/media/" MEDIA_ROOT = '/Users/myproject/media/' Here is models.py UPLOAD_FILE_PATTERN="assets/uploaded_files/%s/%s_%s" def get_upload_file_name(instance, filename): date_str=datetime.now().strftime

404 when requesting url of saved image in media directory using django rest framework

瘦欲@ 提交于 2019-12-12 05:28:38
问题 I am developing a django rest api using the django rest framework. The rest api manages clothing items to be shown in an android application and has a model named Clothing which has an ImageField for showing the clothing item. From the django admin, I can add an image and save the Clothing model instance by clicked the save button below, which I do click and then get a success message: I then check my media/clothing/ file which is configured to save the static files and see that the image has

Why is {% load static %} a dependency for {% get_media_prefix %}?

。_饼干妹妹 提交于 2019-12-11 17:47:36
问题 I've been using {% get_media_prefix %} for a very long time. I was explaining this to someone when he pointed this out. Why do I need to declare {% load static %} in order to use it? It even uses in the documentation's example code here. To an extent I understand that static files and media files are similar in nature. Even when we use them with combination of nginx+gunicorn, nginx handles both of them(we let everything else proxy, but not these). But still we have a separate MEDIA_URL and

Django - Displaying video with jwplayer

怎甘沉沦 提交于 2019-12-11 13:26:19
问题 I am currently trying to display a video on a website using jwplayer. The view for the page is def video(request): return render_to_response('video_player/video.html', context_instance=RequestContext(request) And the html template being used contains this in the head: <script type="text/javascript" src="/jwplayer/jwplayer.js"></script> And this in the body: <div id="myElement">Loading the player...</div> <script type="text/javascript"> jwplayer("myElement").setup({ file: "{{ MEDIA }}videos

django admin static files stopped working after upgrade to 1.4

牧云@^-^@ 提交于 2019-12-10 16:47:11
问题 Setting up static files in django has always been a nightmare to me. When it comes to dealing with django static content I get depressed and feel dumb and stupid. I never really cared about getting admin media files served as static ones since I barely use admin interface and there is no impact on performance. It has worked quite ok with this dev setup until I upgraded to 1.4 settings.py MEDIA_ROOT = 'd:/~Sasha/Portman/media/' MEDIA_URL = 'http://localhost:8000/media/' ADMIN_MEDIA_PREFIX = '

Django media URL not found

我与影子孤独终老i 提交于 2019-12-07 07:27:10
问题 I'm running into a strange issue,hope some where else some one can had faced the same problem.My problem which is like, the stored media in django application are not able to serve through MEDIA_ROOT URL.When I tried to get list of media files that are saved in my application using URL myhost/media/ it showing all the media files.But when I tried to view on of them using URL myhost/media/image.jpg, got error Requested page not found. Error Track Trace: Using the URLconf defined in myapp.urls,

Django media URL not found

十年热恋 提交于 2019-12-05 19:12:02
I'm running into a strange issue,hope some where else some one can had faced the same problem.My problem which is like, the stored media in django application are not able to serve through MEDIA_ROOT URL.When I tried to get list of media files that are saved in my application using URL myhost/media/ it showing all the media files.But when I tried to view on of them using URL myhost/media/image.jpg, got error Requested page not found. Error Track Trace: Using the URLconf defined in myapp.urls, Django tried these URL patterns, in this order: 1.^media\/(?P<path>.*)$ The current URL, ~myapp/media

django 1.10 media images don't show

你离开我真会死。 提交于 2019-12-04 12:55:30
I have had django media images working in an existing django 1.7 project by adding the following to site urls.py: urlpatterns = patters( url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}), ) This url structure doesn't work in django 1.10 and so I changed it to the reccommended here Django MEDIA_URL and MEDIA_ROOT : urlpatterns = [ ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) This fails to render any uploaded media images. Is there an equivalent media url patter for django 1.10 I can use? You can use this:

Django and Nginx X-accel-redirect

你离开我真会死。 提交于 2019-12-04 01:41:57
问题 I have been fumbling around with trying to protect Django's media files with no luck so far! I am simply trying to make it where ONLY admin users can access the media folder. Here is my Nginx file. server { listen 80; server_name xxxxxxxxxx; location = /favicon.ico {access_log off; log_not_found off;} location /static/ { alias /home/{site-name}/static_cdn/; } location /media/ { internal; root /home/{site-name}/; } location / { this is setup and working. Didn't include Code though } My Url

Page not found 404 Django media files

て烟熏妆下的殇ゞ 提交于 2019-12-03 05:40:54
问题 I am able to upload the files to media folder( '/peaceroot/www/media/' ) that I have set up in settings.py as below MEDIA_ROOT = '/peaceroot/www/media/' MEDIA_URL = '/media/' But through admin I tried to access the uploaded image file http://localhost:8000/media/items/1a39246c-4160-4cb2-a842-12a1ffd72b3b.jpg then I am getting 404 error. The file exists at peaceroot/www/media/items/1a39246c-4160-4cb2-a842-12a1ffd72b3b.jpg 回答1: Add media url entry in your project urlpatterns: from django.conf