79758814

Date: 2025-09-08 11:25:00
Score: 0.5
Natty:
Report link

This is my new approach.

But it does not work as expected;

When I close the page and restart the development server, it works perfectly fine for the first time. But after that it does not work. I surely don't have any idea about what's going one.

class homeView(View):
    def get(self, request):
        data = recipemeal.objects.all().order_by("-id")
        
        context ={
            "recipes":data,
            "form":RecipeForm()
        }
        return render(request, "index.html", context)
    
    def post(self, request):
        form = RecipeForm(request.POST)
        
        if form.is_valid():
            form.save()
            
        data = recipemeal.objects.all().order_by("-id")
        context = {
                "recipes": data,
                "form": RecipeForm()
            }
        
        return render(request, "index.html", context)
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: DAVE LOVE