2

I am facing an Odd problem in django. It throws me a message that ImproperlyConfigured

below is my Views.py

class ArticleListCreateGet(ListAPIView, CreateAPIView):
    queryset = Article.objects.all()
    serializer_class = ArticleSerializers

and below is my serializers.py

class ArticleSerializers(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Article
        fields = ['author', 'title', 'body', 'category']

and below is my models.py

from django.db import models
from django.contrib.auth.models import User

class Author(models.Model):
    name = models.TextField(max_length=50)

class Category(models.Model):
    name = models.CharField(max_length=100)

class Article(models.Model):
    author = models.ForeignKey(Author, on_delete=models.CASCADE)
    title = models.CharField(max_length=200)
    body = models.TextField()
    category = models.ForeignKey(Category, on_delete=models.CASCADE)

and this my urls.py

url('^api/v1/article$', views.ArticleListCreateGet.as_view(), name='articleGetAndPost')

I guess my everything is ok but when i hit this url

http://127.0.0.1:8000/api/v1/article

It throws me this error message

ImproperlyConfigured at /api/v1/article

Could not resolve URL for hyperlinked relationship using view name "author-detail". You may have failed to include the related model in your API, or incorrectly configured the `lookup_field` attribute on this field.

Request Method:     GET
Request URL:    http://127.0.0.1:8000/api/v1/article
Django Version:     2.2.and bla bla bla bla bla bla bla

How can get rid of this problem?

dudd
  • 372
  • 1
  • 4
  • 13
  • can you add ***complete `urls.py`***? – JPG Jun 17 '19 at 04:56
  • Maybe [this](https://stackoverflow.com/questions/20550598/django-rest-framework-could-not-resolve-url-for-hyperlinked-relationship-using) can help you out. – Jordan Mora Nov 13 '19 at 12:52

0 Answers0