Hi ALL, 

I was trying to render user-uploaded media files into the template but it 
 throws out a 404 only on the media files. The all other context variables 
are rendered except the media files. I am using django 1.9.1 and python 
2.7.9.


Here's the  settings file. I only included the code relevant to the current 
issue.

settings.py

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'pi_app',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',


TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS':[os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.template.context_processors.i18n',
                'django.template.context_processors.media',
                'django.template.context_processors.static',
                'django.template.context_processors.tz',
                'django.contrib.messages.context_processors.messages',
                
            ],
        },
    },
]



STATIC_URL = '/static/'

STATIC_PATH = (os.path.join(BASE_DIR, 'static'),
               '/var/www/static/',)

STATICFILES_DIRS = (
    STATIC_PATH,
)
MEDIA_URL = '/media/'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')


Here's is my urls.py

from django.conf.urls import url
from django.conf import settings
from django.conf.urls.static import static

 
from . import views

urlpatterns = [
    url(r'^$', views.UserMainView.as_view(), name='index'),
    url(r'^upload_file/$', views.upload_file, name='upload_file'),
    url(r'^video_entry/(?P<video_slug>[\w-]+)/$', views.video_entry, 
name='video_entry'),
    

] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)


Here is my views.py

def video_entry( request, video_slug):
    video_details = Entry.objects.get(slug = video_slug)
    context = {'video_details': video_details}
    context['presentation_video']= video_details.video




-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f33e0c1e-8001-49b2-996d-52dd1c1b36bd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to