<https://stackoverflow.com/posts/78314829/timeline>

I'm setting up a CRUD system with Django, using Class-Based Views. 
Currently I'm trying to figure out how to handle HTTP PUT and DELETE 
requests in my application. Despite searching the Django documentation 
extensively, I'm having trouble finding concrete examples and clear 
explanations of how to submit these types of queries to a class-based view.

I created a view class named CategoryView, extending from: 
django.views.View, in which I implemented the get and post methods 
successfully. And I want to build my urls like this:

   1. New Category: 127.0.0.1:8000/backendapp/categories/create 
   2. List all Category: 127.0.0.1:8000/backendapp/categories/ 
   3. Retrieve only one Category: 127.0.0.1:8000/backendapp/categories/1 
   4. Etc... 

However, when I try to implement the put and delete methods, I get stuck.

For example :
from django.views import View 

class CategoryView(View):
     template_name = 'backendapp/pages/category/categories.html'
     
     def get(self, request):
          categories = Category.objects.all()
          context = { 'categories': categories }
          return render(request, self.template_name, context)

     def post(self, request):
          return

     def delete(self, request, pk):
          return

     def put(self, request):
          return

I read through the Django documentation and found that Class-Based Views 
support HTTP requests: ["get", "post", "put", "patch", "delete", "head ", 
"options", "trace"].

link: 
https://docs.djangoproject.com/en/5.0/ref/class-based-views/base/#django.views.generic.base.View
 
<https://stackoverflow.com>

Despite this, I can't figure out how to do it.

So I'm asking for your help to unblock me.

I looked at the Django documentation and searched online for examples and 
tutorials on handling HTTP requests in class-based views. I also tried 
experimenting with adding the put and delete methods to my CategoryView 
view class, but without success. I expected to find resources that clearly 
explain how to integrate these queries into my Django application, as well 
as practical examples demonstrating their use. However, I haven't found a 
working solution and am now seeking help from the community to overcome 
this difficulty.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b1ecd4a7-5946-4da5-80ae-5923b6648a70n%40googlegroups.com.

Reply via email to