The urls matches what I need, and also Swagger let me provide an employee_id as a path parameter which is what I expect, but Django responds with a 404:
When reversing the url, it seems to me that the <int:employee_id> notation on the router it’s not working as if it were inside a path(), therefore the url with the path parameter doesn’t really exist.
Before trying to manipulate the viewset into giving you the urls you want, you should try reworking the path argument to register. It looks like you’re supplying it a regular expression, r'<int:employee_id>', but the contents of that expression are what we’d typically supply to a django.urls.path call.
You need to treat that argument as if it were a re_path call instead.
Here is an example of a URL which will return an answer to a question. The models look a little like this.
class Quiz(models.model):
id
class QuizQuestion(models.model):
id
quiz = models.ForeignKey(Quiz)
class QuizAnswer(models.model):
id
question = models.ForeignKey(QuizQuestion)
In order to list all questions or get a single question, I use this URL
hi, happy to find you’re question , could you help me ?
i have this simple viewset and serializer
class UploadSerializer(serializers.ModelSerializer):
class Meta:
model = Account
fields = ('image',)
class UploadViewSet(viewsets.ModelViewSet):
queryset = Account.objects.all()
serializer_class = UploadSerializer
i want to access the id that passed in the url , how could I ?
I tried a lot lot lot of solution but nothing help me…
sorry for my English ,