-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Getting started issues. #1249
Comments
#2 is still my primary issue, so I thought I'd try to put out as much info as possible. It seems really bizarre that django-rest-framework works perfectly unless I'm also running django-admin. The beginner tutorial would likely assume the user is taking something like the "Poll" django app, which means they'd be logged into django admin. (django1) taras@desktop:~/Projects/tutorialsite$ pip freeze I'd be more than happy to write up an updated walkthrough for the community when I figure this out, so others will benefit by exploring this first-attempt issue. Thanks in advance for any help. |
Hiya, Apologies for the delay. I believe the issue here is that the quickstart example is actually broken in a non-obvious way - there's no view for permissions - if there are no permissions in the database that'll work fine, it never needs to generate URLs linnking to the permission instances, but if there are permission instances then it'll break in the ay you're seeing. Looks like we need to tweak the example to either:
|
Hey thanks, and my first issue was fixed by #1274. I managed to fix the primary issue adding permissions, so no rush for my own purposes on this. |
What permissions need to be added? Have the same problem Relevant xkcd, http://xkcd.com/979/ |
Currently breaks if you have an permission instances in Django's auth.permissions table. |
Odd, when I moved the API stuff out of my root project and into separate apps individually, it stopped being broken: I can use the API with or without logging in, and admin still works Instead of putting everything in ///urls.py I'm using ///urls.py & api.py |
@synotna Moving Users-related code from urls.py and into an app did not fix it for me. @tomchristie I've been working on this same issue for three hours and getting nowhere. I've got the lookup_field set, and the related model is all clearly defined as far as I can tell. Just can't seem to fix this error when visiting /api/users. The code I'm using was copied from the sample project and then lightly modified. Here's what I've got as of now: Reading StackOverflow answers to this and the docs isn't getting me there. Just can't see what I'm doing wrong. Thanks for any clues. |
@shacker Looks like you need to (also) set the Also see: http://www.django-rest-framework.org/api-guide/serializers#how-hyperlinked-views-are-determined We could certainly do with some easier way of helping users resolve the issue when hyperlinked serializations don't match up with the views being defined, but I'm not too sure how to approach it. |
Bingo! Adding As to providing more assistance to new users, here, I would suggest:
"Could not resolve URL for hyperlinked relationship using view name "user-detail". You may have failed to include the related model in your API, or incorrectly configured the unfortunately, doesn't quite get the developer to the right solution. Thanks again. |
Thanks @shacker - great points. |
Hi! I have a similar issue with the same error message, trying to do the manul ViewSet on the User class, but I cannot get it working. I know that there is a shortcut for the user to just extend ModelViewSet, but I want to do the work manually (to understand). Could you tell me why I got the I would really appreciate some help. |
Hi, I've got this issue or a very similar one also. I'm new to both django and django-rest. I added the lookup_field value to the user's 'Meta' class as @shacker says above. I still get this error
It's entirely mysterious what's going on here to me. you can see the code at https://github.com/scotartt/commentarius/tree/master/decommentariis |
Just wanted to chime in, I'm a new user, was running through the steps of the Example here: Though the above discussion temporarily solves the issue -- I just logged out of the admin area and tried again -- it does not make any sense to me as I'm new to the Django REST framework and fairly new to Django. Given this is going to be most newbie's immediate experience with the framework, and not everyone is going to find this discussion by Googling (I frequently assume when things go wrong that I'm doing it wrong, so might not search for the solution right away), it would seem wise to update at the very least the instructions to new users with a workaround in plain English, or remove the broken example. I appreciate this discussion, glad I was able to workaround. Now on to the Quickstart and Tutorial... :) |
http://www.django-rest-framework.org/#examplefrom django.contrib.auth.models import Permission class PermissionViewSet(viewsets.ModelViewSet): need to add additional |
I was also able to fix this issue temporarily by explicitly declaring the fields for the user serializer, excluding the permissions field, like this: class UserSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = User
fields = ('username', 'etc',) lookup_field did not work in my case. |
^ Is the change we oughta make to the example yes. |
Should the example page include a UserSerializer? I'll update the documentation but I'm not sure what direction you'd like to take. |
The comment from myrubapa worked for me. Apparently we just need a few more __SetViews to address additional models. Any field that appears as a REST hyperlink seems to need such a view. |
Yes, it needs too - not including an explicit UserSerializer doesn't work because it'll default to including a field that is a hyperlinked relationship to permissions, which aren't also included as a view. |
Hi, I have tried the Update example code #1550, but still got the error "Could not resolve URL for hyperlinked relationship using view name 'permission-detail'" when I login and access url "/user/", what's wrong? |
Closing this off given the 2.4.0 release. The deprecation of the |
I just started integrating django-rest-framework with an existent project and I am facing similar issues when following the quick start guide, I've added views for Users, Permissions, Groups but I am not sure what other relationships need to be properly configured in order for the |
Hi guys, not sure if there is another issue for that, but I'm having similar issues as @cabello - As soon as I try change my serializer to extend HyperlinkedModelSerializer, I get the error :/ |
An easy fix:
|
Ok, I have a full and valid fix, add the following Serializers: from django.contrib.auth.models import Permission
class PermissionSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Permission Views: class PermissionViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows permissions to be viewed or edited.
"""
queryset = Permission.objects.all()
serializer_class = serializers.PermissionSerializer Urls: router.register(r'permission', PermissionViewSet) |
I'm a new user to django-rest-framework and ran into several issues, so I thought I'd post them here to see if any pieces of the quickstart docs should be updated to help others avoid the same.
On django 1.6 the first line of the home page example blows up:
from django.conf.urls.defaults import url, patterns, include
needs to be:
from django.conf.urls import url, patterns, include
I took the basic poll site with django 1.6 (I also tried 1.5.5 and ran into the same issues) with py3.3.2 and pip installed the framework, updated the settings.py as per home page, and completely overrode the urls.py with what was on the home page of django-rest-framework.
At first, everything didn't work due to:
In template /home/taras/Envs/django1/lib/python3.3/site-packages/rest_framework/templates/rest_framework/form.html, error at line 9
Could not resolve URL for hyperlinked relationship using view name "permission-detail". You may have failed to include the related model in your API, or incorrectly configured the
lookup_field
attribute on this field.I tested in another browser where I was not logged into django-admin as an admin beforehand, and that worked perfectly.
I also tried this on another site, leaving the main urls.py file with /admin/ urls intact and had the same issue.
I tried changing the default permissions thinking that might be somehow related to:
'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAdminUser',),
and the non-logged browers got a correct json message saying credentials were not provided, and still a stack trace on the other.
Any help with #2 would be great, and let me know if you need additional info. Thanks!
The text was updated successfully, but these errors were encountered: