我想在Django框架中执行UPDATE和DELETE操作,我做了GET和POST操作。请帮助我做UPDATE和DELETE操作。
views.py
class SettingprofileViews(viewsets.ModelViewSet):
queryset = Setting_profile.objects.all()
serializer_class = SettingprofileSerializer
models.py
class Setting_profile(models.Model):
name = models.CharField(max_length=255, blank=True, null=True)
contact_number = models.CharField(max_length=12, blank=True, null=True)
email = models.EmailField(max_length=100, blank=True, null=True)
address = models.CharField(max_length=500, blank=True, null=True)
serializers.py
class SettingprofileSerializer(serializers.ModelSerializer):
class Meta:
model = Setting_profile
fields = '__all__'
urls.py
router = routers.DefaultRouter()
router.register('api/settingprofile', views.SettingprofileViews)
urlpatterns = [
path('', include(router.urls)),
]
1条答案
按热度按时间mrzz3bfm1#
ModelViewSet已实现PUT和DELETE HTTP方法的操作。
See: https://www.django-rest-framework.org/api-guide/viewsets/#modelviewset
这意味着如果您执行HTTP请求: