django-media

Django: Include Media (css/js) in Class-Based Views

会有一股神秘感。 提交于 2019-12-02 04:24:32
I am updating old django code from method-based views to class-based views. I know how to include media (css/js) in forms via the Media class How can I use the media class if my class based view does not contain any forms? CSS/JS are usually managed in the template itself and not in the view. See https://docs.djangoproject.com/en/1.10/howto/static-files/ For example, use base.html: <!DOCTYPE html> <html> <head> <title> {% block page_title %}{{ page_title }}{% endblock %} </title> {% block css %} {% endblock %} </head> <body> {% block main %} {% endblock %} {% block scripts %} {% endblock %} <

Django and Nginx X-accel-redirect

99封情书 提交于 2019-12-01 08:03:22
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 File urlpatterns = [ url(r'^media/', views.protectedMedia, name="protect_media"), ] And my view def

Django cannot find my media files (on development server)

霸气de小男生 提交于 2019-11-30 14:55:14
The media is currently on my local development machine. My MEDIA_ROOT, MEDIA_URL, ADMIN_MEDIA_PREFIX and are specified as below: MEDIA_ROOT = os.path.join(os.path.dirname(__file__), "media") MEDIA_URL = '/media/' SITE_URL = 'http://localhost:80' ADMIN_MEDIA_PREFIX = '/media/admin/' There is no 'admin' folder but that shouldn't make a difference I don't think. In the urls.py file I have: (r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}), I am at a loss as to what I should do to get it working. [I am trying to learn django and am working with an

Django cannot find my media files (on development server)

倖福魔咒の 提交于 2019-11-29 20:19:01
问题 The media is currently on my local development machine. My MEDIA_ROOT, MEDIA_URL, ADMIN_MEDIA_PREFIX and are specified as below: MEDIA_ROOT = os.path.join(os.path.dirname(__file__), "media") MEDIA_URL = '/media/' SITE_URL = 'http://localhost:80' ADMIN_MEDIA_PREFIX = '/media/admin/' There is no 'admin' folder but that shouldn't make a difference I don't think. In the urls.py file I have: (r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}), I am at a

Django serving media files (user uploaded files ) in openshift

懵懂的女人 提交于 2019-11-29 07:35:16
问题 I have successfully deployed my Django project in openshift. But I need to be able to serve files that are uploaded by users. I user MEDIA_ROOT and MEDIA_URL for that. I followed this tutorial here, but nothing happened. I had to change MEDIA_ROOT because the one suggested there isn't correct i think. So my MEDIA_ROOT looks like MEDIA_ROOT = os.path.join(os.environ.get('OPENSHIFT_DATA_DIR', ''),'media') MEDIA_URL = '/media/' I added the .htaccess in /wsgi folder with as it says in the article