Hello fellow developpers,
I have a quick question about implement views and urls at best.
I currently have this :
views.py:
from rest_framework.views import APIView
from rest_framework.response import Response
class Article(APIView): def get(self, request):
#Perform Sexy Operations
return Response({"message": "Hello, world!"})
def post(self, request):
#Perform Sexy Operations
return Response({"message": "Hello, world!"})
def put(self, request):
#Perform Sexy Operations
return Response({"message": "Hello, world!"})
def delete(self, request):
#Perform Sexy Operations
return Response({"message": "Hello, world!"})
urls.py:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.conf import settings
from django.conf.urls import include, url
import django.contrib.auth.views
from .views import *
urlpatterns = [
url(r'^api/get/article/$', Articleas_view(), name='get_article'),
url(r'^api/post/article/$', Article.as_view(), name='post_article'),
url(r'^api/modify/article$', Article.as_view(), name='modify_article'),
url(r'^api/delete/article$', Article.as_view(), name='delete_article'),
]
*My Question :*
How to make sure that *ONLY:*
- *GET *Requests can be route with the "api/get/article/" route.
- *POST *Requests can be route with the "api/post/article/" route
- And so on ...
Because, as it's design, nothing prevent me to trigger the "get" behavior
from the "post" route.
Which is not a super big deal, however, I'd prefer to forbid it.
Is Class-Based views the best way to implement views ? I find it very cool
and intuitive to be honest.
Thanks a lot for your answers and have a good day.
Jonathan DEKHTIAR
--
You received this message because you are subscribed to the Google Groups
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.