BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_URL = '/static/'
STATIC_PATH = (os.path.join(BASE_DIR, 'static'), '/var/www/static/',)
STATICFILES_DIRS = ( STATIC_PATH,)MEDIA_URL = '/media/'
class Entry(models.Model): VIDEO_ENTRY_TYPE = ( ('SEMINAR', 'Seminar'), ('LECTURE', 'Lecture'), ('TALK', 'Talk'), ) user = models.ForeignKey(User) video = models.FileField(upload_to='video_entries') entry_type = models.CharField(max_length=100, choices=VIDEO_ENTRY_TYPE) title = models.CharField(max_length=250)
class EntryForm(ModelForm): class Meta: model = Entry fields = ['video', 'entry_type', 'title'] from django.shortcuts import renderfrom django.http import HttpResponseRedirectfrom django.http import HttpResponsefrom django.views.generic import ListView
from . models import User, Entry, EntryForm
class IndexView(ListView): template_name = 'pi_app/index.html' context_object_name = 'latest_seminars' def get_queryset(self): return Entry.objects.filter(entry_type='SEMINAR').order_by('-pub_date') [:10] def get_context_data(self, **kwargs): context = super(IndexView, self).get_context_data(**kwargs) context['latest_lectures'] = Entry.objects.filter(entry_type='LECTURE').order_by('-pub_date') [:10] context['latest_talks'] = Entry.objects.filter(entry_type='TALK').order_by('-pub_date') [:10]from django.conf.urls import urlfrom django.conf import settingsfrom django.conf.urls.static import static
from . import views
urlpatterns = [ url(r'^$', views.IndexView.as_view(), name='index'), url(r'^upload_file/$', views.upload_file, name='upload_file')]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
<!DOCTYPE html>
{% load staticfiles %}
<html> <head> <title>Homepage</title> </head> <body> <h1> Welcome {{ user }} </h1>
<!-- SAMPLE BLOCK THAT I WANT THE MEDIA FILES RENDERED -->
{% block seminar %} <section id="latest_seminars"> <h2>Most Recent Seminars</h2> {% if latest_seminars %} <ul> {% for seminar in latest_seminars %} <video width="350", height="250", alt="{{ seminar.title }}" controls > <source src= "{{MEDIA_URL }} {{ seminar.video }}"/> </video> {{ seminar.title }} by {{ seminar.user }} {% endfor %} </ul> {% endif %} </section> {% endblock seminar %}
--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/66cb760a-96d3-4998-beec-1f6a947b9259%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/55af2a30.c25e460a.f394.239a%40mx.google.com.