Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Redirect to post details from new_post doesn't work
I have a section named forum in my project where users can post and discuss. During creating a new post, when I try to save my new post as a user (pic)this error occurs. Also, I am trying to save the username as well to show further which user creates the post. Actually problem shows when I try to save this file I tried in following way: models.py: class Post(models.Model): user_id = models.ForeignKey(User, on_delete =models.CASCADE) title = models.CharField(max_length = 500, blank = False) description = models.TextField() def __str__(self): return self.title views.py: class PostCreate(CreateView): model = Post fields=['title','description'] template_name = 'post_form.html' def self(self, request): mdoel.user_id = request.user.id return redirect('website:details',{'post': model}) urls.py from django.conf.urls import url from .views import UserFormView , index , user_login,Forum,Details,PostCreate app_name = 'website' urlpatterns = [ url(r'^$',index,name = 'index'), url(r'^register/$',UserFormView.as_view(),name = 'register'), url(r'^login/$', user_login, name= 'login'), url(r'^forum/$',Forum, name = 'Forum'), url(r'details/(?P<post_id>[0-9]+)/$',Details,name= 'details'), url(r'add/$',PostCreate.as_view(),name = 'newPost') ] -
Is models in my django applications correctly defined?
I'm learning Django and created a University application in django project. Now I want to know whether the relationships defined in my models.py is correct or not? from django.db import models class University(models.Model): name = models.CharField(max_length=100) courses = models.CharField(max_length=500) def __str__(self): return self.name class Student(models.Model): GENDER_CHOICES = ( ('M', 'Male'), ('F', 'Female'), ) name = models.CharField(max_length=200) roll_number = models.IntegerField(max_length=10) gender = models.CharField(max_length=1, choices=GENDER_CHOICES) university = models.ForeignKey(University, primary_key=True) classes = models.ManyToManyField(Classes, blank=True, related_name="classes") def __str__(self): return self.name class Classes(models.Model): name = models.CharField(max_length=100) attendee = models.CharField(max_length=100) student = models.ManyToManyField(Student, blank=True, related_name="students") def __str__(self): return self.name -
How to only render bundles that exist in django webpack
I am using django webpack loader to enable angular webpage hosting. The issue I am running into is including the render bundles {% load render_bundle from webpack_loader %} {% load static %} <!doctype html> <html lang="en"> <head> <base href="/"> <title>Angular/TypeScript Hello World Project</title> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="description" content="Angular Hello World Starter"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" /> <link rel="stylesheet" type="text/css" href="{% static 'angular/assets/styles/styles.css' %}"> </head> <body> <main class="container"> <app-root> Loading... </app-root> <br /><br /> </main> {% render_bundle 'runtime' %} {% render_bundle 'polyfills' %} {% render_bundle 'styles' %} {% render_bundle 'vendor' %} {% render_bundle 'main' %} </html> When I run the above code it works, however when I run angular build in prod. I get the error Cannot resolve bundle vendor. So I need to only render the bundles if they exist. How do I do this? Also, it would be nice if I had a loop through all bundles to include them how do I do this? -
Pass Django SECRET_KEY in Environment Variable to Dockerized gunicorn
Some Background Recently I had a problem where my Django Application was using the base settings file despite DJANGO_SETTINGS_MODULE being set to a different one. It turned out the problem was that gunicorn wasn't inheriting the environment variable and the solution was to add -e DJANGO_SETTINGS_MODULE=sasite.settings.production to my Dockerfile CMD entry where I call gunicorn. The Problem I'm having trouble with how I should handle the SECRET_KEY in my application. I am setting it in an environment variable though I previously had it stored in a JSON file but this seemed less secure (correct me if I'm wrong please). The other part of the problem is that when using gunicorn it doesn't inherit the environment variables that are set on the container normally. As I stated above I ran into this problem with DJANGO_SETTINGS_MODULE. I imagine that gunicorn would have an issue with SECRET_KEY as well. What would be the way around this? My Current Approach I set the SECRET_KEY in an environment variable and load it in the django settings file. I set the value in a file "app-env" which contains export SECRET_KEY=<secretkey>, the Dockerfile contains RUN source app-env in order to set the environment variable in the container. … -
Django form not submitting upon click
I don't know why my code is not submitting, i search on the internet and cannot find any solution, please someone should help me go through this code {% extends 'root/base.html' %} {% block title %}{{title}}{% endblock %} {% block body %} <div class="container"> <div class="row"> <div class="col-md-6"> <form method="post" action="{% url 'shopapp:signup' %}"> {% csrf_token %} {% for field in form %} {{field.label}} <p>{{field}}</p> {% endfor %} <p><input type="submit" value="Signup" class="btn btn-danger"></p> </form> </div> </div> {% endblock %} -
Retrieve selected choices from Django form ChoiceField
I'm attempting to make a search functionality on my Django web app. The idea is that users will go to the front page and be able to select from a drop down list of properties (ie. the OS, compiler, etc) and then submit their search which should return a list of matching builds. I have the ChoiceField form set up and I know the code I need to run to get the proper build in my next view. What I don't know is how to pass the values the user selected when they hit submit to the next view so I can filter based on those choices. Any help? forms.py from .models import * class BuildForm(forms.Form): build_OPTIONS = Builds.objects.values().distinct() ... Build_type = forms.ChoiceField(widget=forms.Select(), choices=build_OPTIONS) views.py from .forms import BuildForm def index(request): builds = BuildForm() return render(request, 'ReportGenerator/index.html', {"builds":builds}) templates/App/index.html {% if builds %} <h2>Pick a Build</h2> <form method="POST" class="build-form">{% csrf_token %} {{ builds.as_p }} </form> {% else %} <p>No reports are available.</p> {% endif %} -
Django template language syntax
I'm learning django and i'm blocked on a template syntax error. I have this function in my views.py : def AccountUpdateView(request): template_name='portal/accountupdate.html' context = {"forms":UserForm} return render(request,template_name,context) There is my template : <form action="/account/update/" method="POST"> <ul> {% csrf_token %} {% for form in forms %} <li>{{form.label}} <input type="text" name="{{form.name}}" maxlength="32" required="" id="id_{{form.name}}" value="{{PLEASE HELP ME !!!}}"> </li> {%endfor%} </ul> <input type="submit" value="Metre a jour" /> </form> Well, i'm trying to get in the "value" of each form on my template by the current registered user known in django by the call {{user}} And i would to auto place the values of each forms. I think a solution is to use the form.name (for the example of the case 'username') and in the value call a thing like this : user.form.username It doesn't work and i know that i was dream to hope this exotic call don't work... If any have a solution :) Thank's you ! -
can't pre-populate a django database
so I've been following this guide from Django 1.1 but I'm actually using Django 2 for how to pre-populate Django database I'm using SQLite database and this is my code with Faker library but it just won't run when I want to run it in the CMD. Please help me if you can: This is my first file which is the script for populating the database: (populate_first_app.py) import os os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'first_project.settings') import django django.setup() ## FAKE POPULATION SCRIPT: import random from first_app.models import AccessRecord,Webpage,Topic from faker import Faker # Creating a fake generator: fakegen = Faker() topics = ['Search', 'Social', 'Marketplace', 'News', 'Games'] def add_topic(): t = Topic.objects.get_or_create(top_name=random.choice(topics))[0] t.save() return t def populate(N = 5): for entry in range(N): # GET THE TOPIC FOR THE ENTRY: top = add_topic() # Create the fake data for that entry: fake_url = fakegen.url() fake_date = fakegen.date() fake_name = fakegen.company() # Create the new webpage entry: webpg = Webpage.objects.get_or_create(topic = top, url = fake_url, name = fake_name)[0] # Create a fake access record for that webpage acc_rec = AccessRecord.get_or_create(name = webpg, date = fake_date)[0] if __name__ == '__main__': print("Populating Script!") populate(20) print("Populating Complete!") And finally, this is my models.py file of the only app … -
social-auth-app-django 'social' is not a registered namespace
Python(3.6.7) and Django(2.1), trying to integrate social-auth-app-django. Unlike this post, I've declared SOCIAL_AUTH_URL_NAMESPACE but it doesn't work. Configuration : settings.py : import os # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Application definition INSTALLED_APPS = [ "Microlly", "social_django", "django.contrib.admin", "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles", ] AUTHENTICATION_BACKENDS = [ 'social_core.backends.github.GithubOAuth2', 'social_core.backends.google.GoogleOAuth2', 'django.contrib.auth.backends.ModelBackend', ] MIDDLEWARE = [ "django.middleware.security.SecurityMiddleware", "django.contrib.sessions.middleware.SessionMiddleware", "django.middleware.common.CommonMiddleware", "django.middleware.csrf.CsrfViewMiddleware", "django.contrib.auth.middleware.AuthenticationMiddleware", "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", "social_django.middleware.SocialAuthExceptionMiddleware" ] ROOT_URLCONF = "microblogging.urls" TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", "DIRS": [], "APP_DIRS": True, "OPTIONS": { "context_processors": [ "django.template.context_processors.debug", "django.template.context_processors.request", "django.contrib.auth.context_processors.auth", "django.contrib.messages.context_processors.messages", "social_django.context_processors.backends", "social_django.context_processors.login_redirect", ] }, } ] WSGI_APPLICATION = "microblogging.wsgi.application" SOCIAL_AUTH_URL_NAMESPACE = 'social' SOCIAL_AUTH_GOOGLE_OAUTH2_KEY="SECRET" SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET="SECRET" SOCIAL_AUTH__KEY="ID" SOCIAL_AUTH__SECRET="SECRET" # Password validation # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator" }, {"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"}, {"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"}, {"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"}, ] STATIC_ROOT = os.path.join(BASE_DIR, "static") LOGIN_REDIRECT_URL = "/accounts/" EMAIL_BACKEND = ( "django.core.mail.backends.console.EmailBackend" ) # During development only urls.py : from django.conf.urls import url from django.contrib.auth import views as auth_views from django.urls import include, path, reverse_lazy from Microlly import views app_name = "Microlly" urlpatterns = [ path("", views.index, name="index"), path("accounts/", include("django.contrib.auth.urls")), url('^api/v1/', include("social_django.urls", namespace='social')) ] login.html <a href="{% url "social:begin" "google-oauth2" %}">Google+</a> And the returned error is : NoReverseMatch at /accounts/login/ 'social' is not a registered … -
How to get data from relationship many-many in django?
How to get all product in every oders in templates django Table sql Model.py templates My browser -
Django, python 2.7 : insert multiple records into two related tables
New to Django orm and i need guidance: i want to insert 5 records in a table say 'Table1' with PK 'table1Primary' then insert same number of records into another table 'Table2' with table 1 PK 'table1Primary' as foreign key example:Table1 primary key pk1 pk2 pk3 pk4 Table 2 foreign keys pk1 pk2 pk3 pk4 [i would rather use for loop or any other optimized way rather than writing separate insert statements] code that doesn't work, i am assuming because of this line eft_fulfillment_uid=ef , i end up with 5*5 inserts in second for i in range(5): ef = Fulfillment.objects.create( fullfillment_uid=generateid(), ... ... ) ef.save() for i in range(5): por = OutReq.objects.create( out_req_uid=random.randint(500, 1000000000), eft_fulfillment_uid=ef, ... ... ) por.save() -
Persist PostgreSQL Data with Docker Named Volumes
I've been trying to set up my dockerized Django application so that the database persists. Currently, each time the site is deployed I have to recreate the database and enter all the data. What I would like to achieve is to have the database data persist so that I can deploy it with the default data already set up and entered. So the requirements are as follows: Persist the default database data that should be the starting data for every deployment of the site. A method to backup database data after users have interacted with the site so that it can be recovered in the event of an outage or loss. The updated database data is stored so that it can be recovered, but doesn't overwrite the initial default data that should be in the database each fresh deployment. I understand there are generally two methods for persisting database data. Mapping the volume to a host directory or using an external container. In my compose file I define the volume database_volume as a named volume, however I didn't set external: true. I'm confused as to where to go from here with this setup. How do I configure where exactly it … -
How to run Django project on apache?
I have a Django project and I will have to deploy it to apache server pretty soon but before that I want to test it on my local machine (Windows OS). And what I want to know is how to configure my Apache server on my local machine to make it work with Django projects. -
Template password_reset_form.html does not overwrite the django admin template
Template password_reset_form.html does not overwrite the django admin template my template is in: registration/password_reset_form.html -
Is there a way to create password protected folder with django?
I want to create an application where user can upload their secret documents. Secret means no one can see the document even the super admin of the server can't even see the document. In other words I want system level authentication. Is there a way to do it with Django? How should I overcome this problem? I have a VPS to store files but I want to create separate document folder for each user which can only be accessed by the user. Not even by me or by the server admin. Any idea would be appreciated. What should be my approach? -
Docker Compose ENTRYPOINT and CMD with Django Migrations
I've been trying to find the best method to handle setting up a Django project with Docker. But I'm somewhat confused as to how CMD and ENTRYPOINT function in relation to the compose commands. When I first set the project up, I need to run createsuperuser and migrate for the database. I've tried using a script to run the commands as the entrypoint in my Dockerfile but it didn't seem to work consistently. I switched to the configuration shown below, where I overwrite the Dockerfile CMD with commands in my compose file where it is told to run makemigrations, migrate, and createsuperuser. The issue I'm having is exactly how to set it up so that it does what I need. If I set a command (shown as commented out in the code) in my compose file it should overwrite the CMD in my Dockerfile from what I understand. What I'm unsure of is whether or not I need to use ENTRYPOINT or CMD in my Dockerfile to achieve this? Since CMD is overwritten by my compose file and ENTRYPOINT isn't, wouldn't it cause problems if it was set to ENTRYPOINT, since it would try to run gunicorn a second time … -
JWT Authentication with Django REST Framework
I am having some trouble authenticating requests to a Django REST endpoint. I have a token-auth URL which points towards rest_framework_jwt.views.obtain_jwt_token, e.g.: urlpatterns = [ path('token-auth/', obtain_jwt_token), path('verify-token/', verify_jwt_token), path('current_user/', CurrentUserView.as_view()), ] where CurrentUserView is: class CurrentUserView(APIView): def post(self, request): print(request.user) serializer = UserSerializer(request.user) return Response(serializer.data) if I create a token in the browser by visiting http://localhost/token-auth/, I can then verify it using the command: curl -X POST -H "Content-Type: application/json" -d '{"token":<MY_TOKEN>}' http://localhost/verify-token/ however the same request called to the http://localhost/current_user/ returns a 400 code: curl -X POST -H "Content-Type: application/json" -d '{"token":<MY_TOKEN>}' http://localhost/current_user/ {"detail":"Authentication credentials were not provided."} Framework settings are: REST_FRAMEWORK = { 'DEFAULT_PERMISSION_CLASSES': ( 'rest_framework.permissions.IsAuthenticated', ), 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework_jwt.authentication.JSONWebTokenAuthentication', ), } And Django is being run in a container with the following Dockerfile: FROM python:3 WORKDIR /code COPY requirements.txt requirements.txt RUN pip install -r requirements.txt COPY . . ENV PYTHONUNBUFFERED=1 EXPOSE 8000 -
Django annotate and order by multiple fields
I have the following model: FileObject(models.Model): region = models.ForeignKey() include_in_lookup = models.BooleanField() date = models.DateField() ... I'm trying to fix a query that is supposed to grab the latest entry based on the region and date. The goal is for each region, return the latest (most recently dated) entry (via the datefield) I can achieve that when I use the following query: from django.db.models import Max obj.filter( include_in_source_lookup=True ).values("region__name").annotate(Max("date")).order_by("region__name") >>> [{'region__name': 'Alabama', 'date__max': datetime.date(2018, 8, 23)}, {'region__name': 'Alaska', 'date__max': datetime.date(2018, 10, 20)}, {'region__name': 'Arizona', 'date__max': datetime.date(2018, 11, 4)}, ... Curiously, when I don't include the order_by, It doesn't seem to work in that it returns all the entries in the database. I know this has to do w/ how order_by is used in conjunction with values but am unsure how that works exactly.. Furthermore, If I want to pass a list of values, how can I get consistency given the way order_by works? Eg: GROUP_FIELDS = ['region', 'date'] obj.filter( include_in_source_lookup=True ).values(*GROUP_FIELDS).annotate(Max("date")).order_by(*GROUP_FIELDS) I've tried many variations of .annotate, .values, and .order_by while trying to use a list of values, but can't get the result from the first QuerySet where theres just one region per latest date. What do I need to … -
How do I update a table column with Django?
I'm trying to create an app with a form that when submitted, updates a table in my database based on the info submitted, but I'm not sure how to go about it. Currently, I have a simple mode: class Client(models.Model): company_name = models.CharField(max_length=200) launchpad_id = models.PositiveIntegerField() client_email = models.EmailField() content_id = models.CharField(max_length=200) def __str__(self): return self.company_name + ' | ' + self.content_id and my databases configured like so: DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'django_project', 'USER': 'xxx', 'PASSWORD': 'xxx', 'HOST': 'xxxx', 'PORT': 'xxx', }, 'info': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'reporting_database', 'USER': 'xxx', 'PASSWORD': 'xxx', 'HOST': 'xxx', 'PORT': 'xxx', } } What I want to happen is when I submit my fields through the Client model either in admin or a template, it updates my client_info table in the reporting_database. I cant seem to figure out how to make that connection work though. I would appreciate any direction you can give me. Thanks. -
Refactoring custom save method for a model
In the following model, I am overriding its save method to use field's default value instead of null whenever null is encountered. The method works, but is wordy. Is there a cleaner way of achieving the same? class Activity(models.Model): date_added = models.DateTimeField(auto_now_add=True) number = models.IntegerField(default=0) athlete = models.ForeignKey(Athlete, on_delete=models.CASCADE, default=None) start_date = models.DateTimeField(default=datetime.datetime.now) name = models.TextField(default="Unassigned") country = models.TextField(default="Unassigned") link = models.TextField(default="Unassigned") segment_efforts = models.TextField(default="Unassigned") distance = models.FloatField(null=True) average_speed = models.FloatField(null=True) def save(self, *args, **kwargs): # overriding model's save method to use default field value instead of null, when null is encountered in JSON fields = self._meta.get_fields() for field in fields: field_value = getattr(self, field.name) if field_value == None: field_att = self.__class__._meta.get_field(field.name) default_value = field_att.get_default() field_value = setattr(self, field.name, default_value) return super(Activity, self).save(*args, **kwargs) -
run command in node virtual enviorment inside other django viertual enviorment
I would like run a sh script from Django to create and install node virtual environment inside django virtual environment default for the project. In theory the steps will be, after press button in django template, get the request in a view and run a sh file with a subprocess django syntax tool. The sh file will contain node commands to create the environment. It’s possible ? If it’s yes, anybody could give me a simple guidelines. Thanks in advance. -
Django ManyToManyField.throug
i am pretty new to coding and stuck on this problem since many hours but i couldn't figure out what is the problem. As far as i understand my code well, it seems it should be identical to the one in the django docs, but i can't find my problem. I would like to have a model like the following An article can be bought by different Supplieres (manytomany) Each Supplier as different Articles (manytomany) And i would like to make this through the table 'Details' to get more information and there is the Problem. Since i have added the 'through' table it is not working anymore (sorry for my bad english and stupid question) With kind regards Thomas https://github.com/Val1dor/dj1/blob/master/tutorial/models.py -
Django Form Fields Appear Dynamically
I have a form in my Django app that contains an upwards of 20 fields. It has been requested that I have only the first few fields display. Once those fields are filled out, the next few fields should be displayed, in addition to the previous fields. How might I accomplish this? The following is my forms.py class QuoteForm(forms.Form): premium_station = forms.IntegerField(max_value=2000, min_value=0, required=False, widget = forms.NumberInput(attrs={'class' : 'form-control', 'placeholder' : '# Premium Admin Stations Needed'})) standard_station = forms.IntegerField(max_value=2000, min_value=0, required=False, widget = forms.NumberInput(attrs={'class' : 'form-control', 'placeholder' : '# Standard Admin Stations Needed'})) basic_station = forms.IntegerField(max_value=2000, min_value=0, required=False, widget = forms.NumberInput(attrs={'class' : 'form-control', 'placeholder' : '# Basic Admin Stations Needed'})) messaging_station = forms.IntegerField(max_value=2000, min_value=0, required=False, widget = forms.NumberInput(attrs={'class' : 'form-control', 'placeholder' : '# Messaging Stations Needed'})) auto_attendant = forms.IntegerField(max_value=2000, min_value=0, required=False, widget = forms.NumberInput(attrs={'class' : 'form-control', 'placeholder' : '# Auto Attendants Needed'})) toll_service = forms.IntegerField(max_value=2000, min_value=0, required=False, widget = forms.NumberInput(attrs={'class' : 'form-control', 'placeholder' : '# Toll-Free Services Needed'})) receptionist = forms.IntegerField(max_value=2000, min_value=0, required=False, widget = forms.NumberInput(attrs={'class' : 'form-control', 'placeholder' : '# Receptionist Clients Needed'})) group_paging = forms.IntegerField(max_value=2000, min_value=0, required=False, widget = forms.NumberInput(attrs={'class' : 'form-control', 'placeholder' : '# Group Paging Needed'})) FourG_backup = forms.IntegerField(max_value=2000, min_value=0, required=False, widget = forms.NumberInput(attrs={'class' : 'form-control', … -
Do I have to re-render my page after updating template data
First I have searched and seen another answer, but it doesn't address my need. I am trying to POST data using jQuery/AJAX from my HTML to update a list that is also on my HTML. When I first rendered my template, it had two list-group containers of which the left container is pre populated. two containers The choice made user makes on the left container determines the list group data of the right container. I wanted to send back to the backend Python (server) which selection the user made from the left container, so that I may populate the appropriate list for the second (right) container. This is why I used the POST method using jQuery/AJAX to send users selection. HTML Here is a Plnkr of the HTML Below is the jQuery/AJAX implementation which WORKS. It sends data back to Python (to my views.py): JS/jQuery/AJAX: <script src="https://code.jquery.com/jquery-3.1.0.min.js"></script> <script> $("#leftContainer > a").click(function(event){ event.preventDefault(); $("#leftContainer > a").removeClass("active"); $(this).addClass("active"); var leftDataSet = parseInt($(this).attr("data-set")); var item_selected = $(this).text(); var item_index = $(this).attr("id") //Users selection to send $.ajax({ type:'POST', url:"home/view_results/onclick/", data:{ selected_item:item_index, csrfmiddlewaretoken:"{{ csrf_token }}" }, dataType:"json", success: function(){$('#message').html("<h3>Data Submitted!</h3>") } }) }); $("#rightContainer > a").click(function(event){ event.preventDefault(); $(this).toggleClass("active"); }); </script> views.py #app/views.py from django.shortcuts import … -
How to create multiple card views without copy pasting
Im currently creating a website which shows tv series and movies, I've so far created a cardview which shows only one movie and i obviously want to add more which is where my dilemma is. Is there a way to create more than one cardview in HTML without having to copy and paste a bunch of times? Here is my parent class in Django; <!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> {% if title %} <title> {{ Flix | title }} </title> {% else %} <title> Flix </title> {% endif %} <link rel="stylesheet" href="/static/Css/Parent.css"> </head> <div class="CardView"> <img src= '{% block Images %}{% endblock %}' alt=""> <h5> {% block MovieInfo %}{% endblock MovieInfo %} </h4> </div> <body> </div class="mainContent"> {% block content %}{% endblock %} </body> </html> Here is the HomePage where the movies are displayed; {% extends "Movies/Parent.html" %} {% block Images %} {% for Movie in Movies %} {{ Movie.Image }} {% endfor %} {% endblock Images %} {% block MovieInfo %} {% for Movie in Movies %} <h5> {{ Movie.Name }} </h5> <h5> Rating: {{ Movie.Rating }}</h5> <h5> Date: {{ Movie.Date_Posted }} </h5> {% endfor %} {% endblock MovieInfo %} {% block MovieName %} {% for …