简体   繁体   中英

django-rest-framework using views returns 500 with a POST

I'm trying to get the following to work: http://django-rest-framework.org/examples/views.html in my own django app. When I do a GET it returns 200 and provides the correct response. However, when I attempt a POST all I get is a 500 error. I am completely stumped, it seems so simple I can't figure out what I'm doing wrong.

urls.py:

from django.conf.urls.defaults import patterns, url
from test.testapp.views import ws_list

urlpatterns = patterns('test.testapp.views',
    ...
    url(r'^ws/List/$', ws_list.as_view()),
    url(r'^ws/List/(?P<pk>\d+)/$', ws_list.as_view()),
)

views.py:

...
from djangorestframework.views import View

class ws_list(View):

    def get(self, request, pk=0):
        if pk == 0:
            rtStr = 'GET the whole list'
        else:
            rtStr ="GET request to List %s" % pk
        return rtStr

    def post(self, request, pk=0):
        return "POST request to List %s, with content: %s" % (pk, repr(self.CONTENT))

I've also tried adding in the forms.py for validation but, like I suspected, it didn't do anything. It seems that this should be so easy, I just can't understand why it wont work...

忘记将试用版/添加到Web服务调用中...打开调试有帮助!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM