Blog API with Django Rest Framework 14 of 33 - Hyperlinked Identity Field for URL

preview_player
Показать описание
Blog API with Django Rest Framework 14 of 33 - Hyperlinked Identity Field for URL

** Blog API with Django Rest Framework ** is a project to build a RESTful API service for the blog we created in Advancing the Blog and Try Django 1.9.

RESTful API services allow our applications to connect with other applications using JSON-formatted data. An strong API can enhance our applications ability to provide value to other services and end users. This type of API is very common in modern web application development.

Generally the topics will include:
- Django Project Setup
- Class Based Views (& some Function Based Views)
- Models, Model Forms, Forms, Form Validation
- Integrate Bootstrap front-end framework.
- Django Registration Redux for Authentication/Registration
- And More

We are Coding For Entrepreneurs [TeamCFE] and have built an entire library of content to help you master Django and other web technologies to launch real projects faster. Enroll today for as low as $20/month.

What Technology you'll learn in the Build a Django 1.8 Blog series:
-- Bootstrap (version 3.3): a powerful front-end framework used by thousands of sites around the world. Bootstrap makes it easier to have a responsive web application so it looks awesome on any mobile device and any desktop computer.

All of our tutorials have a simple goal in mind: get you building something real and quickly.
Рекомендации по теме
Комментарии
Автор

Just in case if someone comes back for reference here, if you are getting error as "Could not resolve URL for hyperlinked relationship using view name "posts-api:detail". You may have failed to include the related model in your API, or incorrectly configured the `lookup_field` attribute on this field.
"
and you are using django 2+ then change your url from

path('posts/<slug:slug>/', PostDetailAPIView.as_view(), name='post_detail') to
path('posts/<slug>/', PostDetailAPIView.as_view(), name='post_detail')

and it will work, realized it after spending 2 hour on it 🤷

ejazshaikh
Автор

Adding url using hyperlinkedidentityfield requires lookup properly in view class and serializer class look_up field should be same and and if you do not have that field(look_up) use pk otherwise it will show you error. Model(Tweet) has no obj (tweet_id).
And dont pass name of include url as well as app_specific url, say if you have

in project file
path('api/tweet/', include('tweet.urls'), name='tweet'),
in app.urls file
path('api/tweet/<int:pk>/', TweetDetailView.as_view(), name='detail'),
then in view_name of HyperlinkedIdentityField pass
url = serializers.HyperlinkedIdentityField(view_name='detail', lookup_field='pk')

ListeningBeauty
Автор

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

removed the posts-api:

view_name='delete',
view_name='detail',

this worked for me

my project is using python 3.8.10 ... django 4.0 .. drf 3.13.1

chetty
Автор

What is the use of that lookup_field? And you included slug in that field. can we use any other field of model?

bricssi
Автор

i have a error if a click to the next page it says:
Could not resolve URL for hyperlinked relationship using view name "post-api:postdetail". You may have failed to include the related model in your API, or incorrectly configured the `lookup_field` attribute on this field.

betoEU
Автор

Hey i needed to know when i m creating a URL for my image field, it just gives me path, i need a full fledged URL. On clicking it, the image should open in the browser . Please help, thanks in advance :)

AnujSingh