I have several Django apps within a single project. What I am running into is that I often tend to add the same object(s) to the render call that renders a particular screen.
In this example below, I have a view that displays a form with a dropdown of categories that you can choose from. Now I need to add these categories every time I display the create.html page. This is simplified, but imagine I have 6 more views that could potentially show the create.html page, all of them have to remember to add the categories array.
def createmeeting(request):
if request.method == "POST":
categories = MeetingCategory.objects.all()
// Some error checking, omitted for this example
error_msg = "invalid content"
if error_msg:
return render(request, "meetings/create.html",
{
"categories": categories,
"error_msg": error_msg,
})
else:
// Create the meeting here, omitted for this example
return redirect("/meetings/profile/")
else:
categories = MeetingCategory.objects.all()
return render(request, "meetings/create.html",
{
"categories": categories
})
Is there a better way of handling cases like this?