Getting data from sqlite database by calling it from Django by using HTML forms

I have a HTML template form:

<form action = "" method = "get">
    <label for="movie_title">Filmo pavadinimas: </label>
    <input type="text" name="movie_title">
    <input type="submit" value="OK">
</form>

I want to enter the movie title on that form and get all of the actors that casted in that movie, but I don’t know how to get to that result even after reading the documentation. DB data:

Model for the required table:

class Filmlist(models.Model):
    film_id = models.AutoField(primary_key=True)
    title = models.CharField(max_length=250)
    description = models.TextField(blank=True, null=True)  # This field type is a guess.
    category = models.CharField(max_length=250)
    price = models.DecimalField(max_digits=10, decimal_places=5)  # max_digits and decimal_places have been guessed, as this database handles decimal fields as float
    length = models.SmallIntegerField(blank=True, null=True)
    rating = models.CharField(blank=True, null=True, max_length=250)
    name = models.CharField(max_length=250)

    class Meta:
        managed = False
        db_table = 'film_list'

views file:

def aktoriai(request):
    # print(request.GET)
    objects = Filmlist.objects.filter(title=request.GET['movie_title'])
    return render(request, "aktoriai.html", context={'objects': objects})

So to conclude, I have to enter movie title and get all of those actors show under actors row. Is it possible to do that with Django and HTML?

The direct answer to your question is Yes, it is possible to do that.

Have you worked your way through either or both of the Official Django Tutorial or the Django Girls Tutorial?

If you have, then you may also want to review the Working with forms | Django documentation | Django docs.

Thank you, I will take a loot :slight_smile:

hi Mr Ken
please can you help me in my issue
i had build model to enter employees data in django and the issue is the table in dashboard.html do not show data although it’s saved correctly in add_employees page and i see it in sqlite browser it’s there

Welcome @Mahmoud-AK-Django !

I suggest you open a new topic for this. When you do, please also post your view, model, and template.

When posting code (or templates) here, enclose each file between lines of three backtick - ` characters. This means you’ll have a line of ```, then your code (or template), then another line of ```. This forces the forum software to keep your code properly formatted.

1 Like