1

I have a problem with creating a view with data from the database. I created a view that should download data from videos (var films) and display them, unstable

views.py

from .models import Films

def index(request):
    filmy = Films.objects
    return render(request, 'films/index.html',{'filmy':filmy})

index.html

<h1>Films</h1>
{% for film in films.all %}

{{filmy.summary}}

<br>
{% endfor %}

models.py

class Films(models.Model):
    image = models.ImageField(upload_to='images/')
    summary = models.CharField(max_length=200)

    def __str__(self):
        return self.summary

I only have a blank page.

1 Answer 1

1

Your views.py

from django.shortcuts import render

from django.http import HttpResponse

from .models import Films

# Create your views here.

def index(request):
    films = Films.objects.all()
    return render(request, 'films/index.html',{'films':films})

In index.html

{% for film in films %}
    <p> {{film.summary}} </p>
{% endfor %}

I hope that helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.