django


doing POST on Django Rest Framework with viewsets return “405 - METHOD POST NOT ALLOWED”


I'm trying to create a HiScore Module for my IOS Apps.
I'm stuck on the POST (probably will have the same issue with the PUT, but not sure) part, I'm getting 405 in Postman.
LIST AND DETAILS are working great, so there is no problem with the models, serialisers or views, just something I'm guessing with adding permissions somewhere
views
class UserViewSet(viewsets.ModelViewSet):
queryset = User.objects.all()
serializer_class = UserSerializer
class GameViewSet(viewsets.ModelViewSet):
queryset = HiScore.objects.all()
serializer_class = GameSerializer
class GameTypeViewSet(viewsets.ModelViewSet):
queryset = HiScore.objects.all()
serializer_class = GameTypeSerializer
class GameLevelViewSet(viewsets.ModelViewSet):
queryset = HiScore.objects.all()
serializer_class = GameLevelSerializer
class HiScoreViewSet(viewsets.ModelViewSet):
permission_classes = [AllowAny,]
queryset = HiScore.objects.all()
serializer_class = HiScoreSerializer
serialisers.py
class HiScoreSerializer(ModelSerializer):
image = SerializerMethodField()
class Meta:
model = HiScore
fields = ("user", "game", "gameType", "gameLevel", "points", "image")
def get_image(self, obj):
try:
profile = UserProfile.objects.get(user=obj.user)
return profile.image.url
except:
return None
urls.py
router = DefaultRouter()
router.register(prefix='hiscores', viewset=HiScoreViewSet)
urlpatterns = router.urls
I think you are missing as_view in view according to documentation. Try this:
In views:
hiscores = HiScoreViewSet.as_view({
'get': 'list',
'post': 'create'
})
And in urls:
from rest_framework.urlpatterns import format_suffix_patterns
urlpatterns = format_suffix_patterns([
url(r'^hiscores/$', hiscores, name='hiscores')
])
http://www.django-rest-framework.org/api-guide/viewsets/

Related Links

Wrong url with Django Sorl thumbnail with Amazon s3
How to include HTML header tags in Django Crispy Forms?
Django Admin search query not hitting Postgres index
Django form validation depending on data in formset
Send param from client datatable to django server code
How to redirect logout page in django-userena?
django form is_valid always fails (extending django-registration form)
Retrieve datas from session after redirect
generating sitemap in django
How to add a all the remaining children (i.e a tree) to a selected node for a jstree?
Modify the django models
How to deal with joins in django app using GAE?
How to redirect the login page and check for login session in Django userena
Cumulative count in recoursetree?
Deploy Django Application without Service Interruption / no Downtime
Django No module named path.to

Categories

HOME
porting
awk
css3
case
apache-spark-mllib
owl-carousel
edge
zip
vsm
jax-ws
trac
pattern-matching
project
g++
filechannel
speech-synthesis
intercom
heat
wolframalpha
sar
poedit
pchart
object-storage
windows-server-2003
surveymonkey
mat
intersystems-cache
inversion-of-control
vex
constexpr
memory-address
gojs
reactjs.net
yowsup
imx6
salesforce-communities
modernizr
flatmap
css-position
microsoft-metro
rfc3339
launchctl
posixct
pair-programming
modelsim
excel-dna
vibrate
branch-prediction
flex-monkey
macaulay2
jclouds
shopping
lua-telegram-bot
angular-ui-typeahead
aurora
sklearn-pandas
upx
phpgrid
forwarding
zen-cart
ember-cli-rails
matlab-deployment
jquery-forms-plugin
diff3
umlgraph
phpldapadmin
angular-gettext
sip-server
rmysql
named-parameters
wxformbuilder
jquery-slider
syndicationfeed
visual-studio-express
mysql-error-1044
jammer
ie8-compatibility-mode
isqlquery
printdialog
kaleidoscope
wp7test
idn
nokia-s40
jqueryform
aspmenu
openfaces
duplex
murmurhash
spread
tui

Resources

Encrypt Message