django-media

Using only gunicorn, django, and whitenoise how do I serve media?

…衆ロ難τιáo~ 提交于 2021-01-28 11:11:51
问题 I have my website finally working properly, but media files aren't served when debug = False what should I do? I've went through hell trying to make it work with nginx following this tutorial but it kept breaking and not serving static among other things, so I went with pure gunicorn and whitenoise. I really am not an expert at deploying, only development. Please help. Security isn't a problem with media files because only the admin can upload them, not end-users. Specifically I need to know

Django/Nginx - Error 403 Forbidden when serving media files over some size

有些话、适合烂在心里 提交于 2021-01-20 18:14:43
问题 When user uploads image, it is stored in media folder inside project directory. The problem is that when they want to see it on the website, nginx return 403 Forbidden error for images over approximately 3 Mb. I set nginx.conf client_max_body_size to 8M http { ## # Basic Settings ## client_max_body_size 8M; ... And already changed memory size in settings.py : FILE_UPLOAD_MAX_MEMORY_SIZE = 8388608 When I upload an image under 3 MB, there are no problems, if I upload image over 3 MB, I can see

problem in loading media files into templates

巧了我就是萌 提交于 2020-07-10 07:07:31
问题 My django project is searching for images in /profile/<pk>/myapp/profile_pics/images.jpg instead of myapp/profile_pics/images.jpg similar to this question image isn't uploaded to media root using Django settings.py - MEDIA_ROOT = os.path.join(BASE_DIR, 'media') MEDIA_URL = '/media/' urls.py - urlpatterns = [ path('profile/<int:pk>/', views.profile, name='profile'), ] if settings.DEBUG: urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) views.py - def profile(request,

django 1.10 media images don't show

我与影子孤独终老i 提交于 2020-01-13 04:52:49
问题 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

Adding css class to field on validation error in django

回眸只為那壹抹淺笑 提交于 2020-01-01 04:21:06
问题 I am using Django's modelform and its really good. How can I highlight the actual text box (e.g. border:red ) if there is a validation error associated with it. Basically what i want is to add a class (error) if there is a validation error to a field. 回答1: What about defining error_css_class? http://docs.djangoproject.com/en/dev/ref/forms/api/#styling-required-or-erroneous-form-rows? class MyForm(ModelForm): error_css_class = 'error' 回答2: Expanding upon errx's answer. Add the CSS .error input

Media files not showing on Debug False

Deadly 提交于 2019-12-25 16:49:44
问题 I've just deployed a site with pythonanywhere, when I set to DEBUG mode to False , my media images dissapear, the path of my media folder is not found. I was asking myself what causes this issue and how I can resolve it ? Here is how I configured my settings : STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') MEDIA_ROOT = os.path.join(BASE_DIR, 'media') MEDIA_URL = '/media/' urls.py urlpatterns = [ ... ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Django uwsgi Nginx not serving media files

三世轮回 提交于 2019-12-25 03:44:51
问题 Edit: I've made some progress trouble shooting this issue. For an update on the situation, read the comments and view this post on ServerFault: https://serverfault.com/questions/690836/django-uwsgi-nginx-not-serving-media-files-django-returns-404-status-code?noredirect=1#comment851441_690836 I'm following this tutorial: http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html Everything was going well until I reached the "Basic nginx test" section. When I stopped and

Why does Dajaxice and Dajax uses MEDIAL_URL?

浪尽此生 提交于 2019-12-24 02:24:25
问题 In Dajaxice's installation documentation, it says to set DAJAXICE_MEDIA_PREFIX in settings.py . Later that value is retrieved in the urls.py . In Dajax's installation documentation (which is 2 years old), it says to load the static file like this: <script src="{{ MEDIA_URL }}/js/prototype.dajax.core.js.js" type="text/javascript" charset="utf-8"></script> Why is it using MEDIA_URL ? Shouldn't it be using STATIC_URL since js , css , and img files should be STATIC ? 回答1: You're right, their docs

django - can't see the uploaded media files from apache

一世执手 提交于 2019-12-24 00:49:40
问题 I have two different directory for both media and static. And as I upload the files through the local server (localhost:8000), I can see the uploaded images both by the local server and the apache server. However, when I upload it with apache(localhost), I can't see them. I can only see the static. But when I reload the page served by the local server (not runserver again), I can then see those pictures both by the local server and the apache. What am I doing wrong? Any help will be

Django. Media Files not found

爱⌒轻易说出口 提交于 2019-12-19 11:58:38
问题 Ok, I have a Django 1.10 project. The relevant settings look like this: BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) MEDIA_ROOT = BASE_DIR + "/media/" MEDIA_URL = '/media/' I'm working locally, I can upload images correctly. But when I try to access the image on a template using {{ image.image.url }} , I get a 404. In the terminal I can see this: [06/Sep/2016 18:13:43] "GET /media/folder/uploaded_image.jpg HTTP/1.1" 404 4900 But if I look into my folder, the file is