Questions tagged [django-rest-framework]

Django REST framework stands out as an incredibly dynamic and adaptable set of tools for creating state-of-the-art RESTful Web APIs. Django, on the other hand, represents a top-level Python Web framework designed to foster efficient development and maintain a sleek, practical layout. Crafted by seasoned professionals, it efficiently handles the majority of the complexities that come with web development, freeing you up to concentrate solely on designing your application instead of starting from scratch. Plus, it's completely free and open-source!

Implementing permission-based REST API in Django using groups

I am currently utilizing Django Rest Framework for my login API. I am looking to only allow certain group users to login through the API. I have set up a group and assigned users to that group. I have created a permission class and applied it to my APIView ...

Custom pagination for next/previous links in Django REST framework

When it comes to backend operations, I have integrated the PageNumberPagination as the DEFAULT_PAGINATION_CLASS. Since I am utilizing vue.js along with fetch, there is no need for me to include the entire URL structure provided by django-rest-framework: " ...

Efficiently retrieving Django model relations through JSON

Struggling to properly title this question, but please bear with me as I explain my dilemma. I am in the process of creating an app for my hockey team that involves a django backend and a mobile app using JSON communication (via django-rest-framework). On ...

What is causing the issue with this API request's functionality?

I have set up an API using Django-REST Framework and am currently working on connecting it to my frontend. One of the endpoints I created retrieves the last four winners, and when I test it, everything seems to be functioning properly. async function getL ...

Is there a way to determine the reason why an object is unable to be serialized as JSON?

I'm facing an issue when trying to serialize a simple data object to JSON in Python. I keep getting the error message "TypeError: <api.tests.MemberInfo object at 0x02B26210> is not JSON serializable." Here's the object I'm attempting to serialize: ...

The absence or inaccuracy of CSRF token in Django, Django REST Framework, and Internet Explorer

Our Django App uses REST Framework in a setup with nginx, redis, celery, gunicorn, and PostgreSQL. The system consists of only one App server. For ajax calls, we utilize the following function : $.ajaxSetup({ beforeSend: function (jqXHR, settings) { ...

"Need help passing an API key in the header of a Vue.js project? I recently encountered this issue while using a

How can I include an API key in the header of a Vue.js request? I am using DRF pagination. methods: { getPostData() { axios .get("http://192.168.43.126:8000/api/?page=" + this.currentPage, { headers: { &q ...

Saving access and refresh tokens in Django after receiving a response from Google API

My LMS application is built using Django REST and Vue.js. I authenticate users through Google OAuth2 by: utilizing drf-social-oauth2 on the backend with Google as the authentication provider implementing this wrapper for gapi on the frontend The user cli ...

When attempting to filter a Django Rest Framework view by its primary key in the urls.py file, the API view

Seeking assistance with filtering my APIListView by a specific PK value provided in the URL. Despite having data at the specified PKs, the API output is empty. Any suggestions? Models.py class Item(models.Model): Description = models.CharField(max_le ...

Every time the Django Rest Framework is used in combination with NextJS and Axios, it consistently returns a "not authenticated

After conducting tests on Postman, I received the correct response. However, upon deploying the code for the frontend team, they reported that it consistently returns false... views.py # Verify authentication status def verify(request): info = {} ...

Discover the optimal method for integrating a Next.js CSR React application with Django and PostgreSQL

I have a question about developing a full-stack app. Currently, I am using a Next.js React app on the frontend and a Django app with a PostgreSQL database on the backend. There are two main approaches I have seen to integrate all of these components seaml ...

Adding a question mark to the URL in Django: A complete guide

I have the following urlpatterns: urlpatterns = [ url(r'^tools(?:/tool_one=(?P<tool_one>w+))?/?$', views.ToolsViews.as_view(), name='tools'), ] This results in a URL like this: tools/tool_one=bags I want to add a question mark to the U ...

How to send a Django form using Django REST framework and AngularJS

Feeling a bit lost on how to handle form processing with django, django-rest-framework, angularjs, and django-angular. By using traditional Django techniques, I can generate a model form in my view and pass it over to my template. With the help of django ...

Guide to authenticating users using Vue JS and Django

Currently, I am collaborating on a compact university venture utilizing Vue JS, Django2, and Django Rest Framework. The project involves two distinct user roles with varying actions within the application. The aspect that is leaving me puzzled is the logi ...

The current issue lies with the validation process of the SerializerMethodField

Currently, I am developing my Django DRF application and dealing with two models - Organization and BankAccount class Organization(models.Model): ... class BankAccount(models.Model): is_main = mode ...

Serialization of Django many-to-many relationships involves representing the connections between two

I am looking to establish a model (Source) with a many-to-many relationship to another model (Tag) and create Source objects without duplicating Tag instances in the database. Below are my models: class Tag(models.Model): name = models.CharField(max_l ...

Excluding Fields from Wagtail API Responses: A Quick Guide

When referring to the Wagtail documentation, there is a specific section dedicated to the exclusion of certain fields from the API (). The focus is on how to remove these fields from the perspective of the API consumer by using the URL query parameter ?f ...

Django REST FrameWork JWT prohibits the provision of data and self-decoding

I currently have these API endpoints set up: urlpatterns += [ path('api-token-auth/', obtain_jwt_token), path('api-token-verify/', verify_jwt_token), path('api-token-refresh/', refresh_jwt_token), path('api/', include(router.urls)), ] For ...

Error message from Django due to Cross-Origin Resource Sharing (CORS) issue when attempting

As a newcomer to Django and WordPress, I have encountered an issue while making an API request from HTML-Javascript code embedded in my WordPress page. The API request goes through successfully and is processed by the Django-rest-framework backend, however ...

What is the total amount within a specified date range when retrieved as JSON?

Consider the following JSON structure: { "timesheets": [ { "user": { "username": "erik", "first_name": "Erik", }, &q ...

405 error: NGINX blocking POST method in Django DRF Vue.js application

I have encountered a strange issue while building my ecommerce site. Everything seems to be working fine, except for the forms. When attempting to post content, I keep receiving a 405 method get not allowed error. It's confusing as I am trying to use the P ...

A mobile device is not utilizing cookies for tracking or storing user data

The mobile authentication detection feature suddenly stopped functioning. Whenever I navigate to a page with a form, the form should make an ajax call to fetch additional information for populating the fields based on user authentication. This process work ...

Using Django's triple-quotation syntax for raw SQL insert queries: When receiving data from an AJAX request, Django may interpret null values as None when

Currently, I am actively involved in a project combining Django with React. Through using DRF, I have implemented an API route to execute SQL queries on my PostgreSQL database. However, encountering obstacles with the current code arrangement. In my setup ...

Troubleshooting: Django REST Framework issue with nested serializer data validation

Recently delving into DRF (and Django), I am tackling the challenge of creating a nested serializer to validate the following request data: { "code": "12345", "city": { "name": "atlanta", "state": "Georgia" }, "subregion": ...

Django-oauth2 encountered a 500 error due to the presence of unauthorized URL query parameters in the request

Just starting out with django. Using: oAuth2 + PKCE protocol, Angular, Django-oauth2-toolkit + REST Continuously receiving this error: oauthlib.oauth2.rfc6749.errors.InvalidRequestError: (invalid_request) URL query parameters are not allowed <oauthli ...

Tips on retrieving and showcasing information from various endpoints in React?

I am working with two different endpoints and I need to fetch data from both simultaneously in order to display it in one single element. For example, I want to show data from one table along with the corresponding name from another table if the product id ...

Struggling to update state data with response data in React, despite the response not being empty

I'm currently working on my first React API application and I am facing an issue where the state data appears to be empty even after assigning res.data, which is not empty. Additionally, I am struggling with rendering all of this content inside a div. Whe ...

Finding the center of a polygon in geoJSON using Django

Working on developing a REST API for managing geo-related data. The front-end developer is requesting the centroid of polygons in geoJSON format based on zoom level. Here is the structure of my polygon model: ... from django.contrib.gis.db import mode ...

Experiencing issues with a Django app that utilizes pandas processing, where a specific page is not loading on railway.app but runs smoothly when tested locally

My Django application, which utilizes pandas processing code, is encountering an issue on a specific page when deployed on the service. It consistently presents an application server error, despite functioning properly on a local server. However, it takes ...

Updating access tokens within a Google login component in React by utilizing django-allauth

I recently integrated Google Login into my web app which has a React front-end and Django backend. In the front end, I utilized the react-google-login package to manage all authentication processes, while on the backend, I implemented django-allauth with s ...

Best practices for implementing Django backend authentication with NextJS frontend forms

I've created an API hub using Django and a frontend application with NextJS. Currently, I'm working on implementing authentication from the NextJS app to the Django API and I'm seeking advice on best practices. At the moment, the NextJS app ...

Exploring the Django-Rest-Swagger documentation for effectively documenting the API within Django Rest Framework

I am currently exploring ways to document my API using the swagger generator tool called django-rest-swagger with DRF. At the moment, I am creating views by extending the rest_framework.views.APIView. I prefer not to use viewsets or serializers for writi ...

Tips on converting Django model into desired format for Bootstrap-tables plugin integration

I want to integrate the bootstrap-table plugin with server-side functionality using Django Rest Framework to populate the data on the table. However, I keep getting the message "No matching records found". After some investigation, I discovered that a spec ...

What is the best way to serialize a method within a model?

Is there a way to serialize the get_picture(self) method within this model? I am currently working on a social networking project and I need to serialize this method in order to obtain a JSON URL for the user's profile picture to be utilized in an And ...

Distinguishing Between CORS and JWT: Understand the Variances

After successfully developing and deploying a Django REST API on Heroku, I encountered an issue when trying to fetch the API in Vue CLI. I received a CORS error message, prompting some questions to arise: Should I enable CORS in the backend using a CORS ...

Trouble persisting Vue JS form data to Django Rest database

I am currently working on a project involving Django, Django REST, and Vue JS. I have successfully managed to retrieve information from the API to the Vue JS frontend. However, I am facing an issue where data is not being posted to the Django database when ...

Why am I receiving the message "Error: /api/products/undefined" instead of /api/products/1?

I am facing an issue where I am trying to retrieve data of a single product from "api/products/id" using Django Rest Framework and store it in the Redux state. However, when I refresh the product's page in my React application by going to "localhost:3000/p ...

Resolving the Django REST problem: Implementing additional actions with ListApiView

Working on a new project utilizing the Django REST API framework. Encountering an error when running the project locally: File "/home/asad/PycharmProjects/microshop/venv/lib/python3.8/site-packages/rest_framework/routers.py", line 153, in get_rou ...

Angular Template Parsing Errors with Django REST framework: Fixing the "<" symbol

Recently, I've been working on developing a DRF API integrated with an Angular front end for one of my ongoing projects. Specifically, I have created serializers for User and Device. However, during the process, I encountered an error related to Stati ...

Django's hierarchical structure allows for the implementation of nested

How can I implement nested categories in Django? I am new to Django and have been trying to set this up, but the solutions I found didn't seem to work. class MainCategory(models.Model): name = models.CharField(max_length=50) date_created = models ...

Personalize the JSON formatting in a Django Rest Framework GET request

I'm having an issue with retrieving a filtered list from my MySQL database. The query seems correct, but the JSON output is not as expected: [ { "id": "0038", "name": "Jane Doe", "total_hrs_per_wee ...

Tips for fetching data from a Django REST API endpoint and displaying it in a Flutter Dropdown widget

I am currently working on a project that involves using Django REST for the backend with Flutter dropdown widget to display a list of Country states. However, I am facing challenges in getting the list of states to appear in the dropdown menu. Can anyone p ...

Exploring the integration of Django Rest Framework with Angular

I am just starting out with Django Rest Framework (DRF) and AngularJs. I am trying to figure out the best way to integrate these two technologies. Combining DRF and AngularJs in one project (Most of the tutorials recommend this) Using DRF as the backend ...

How to transform HTML input type with identical names into key-value pairs using jQuery

When the addmorefield button is clicked on this form, two more fields with the same name are appended: <form method="post" id="sampleform" action="#"> <div class="input_fields" style="text-align:center"> <input type="text" name="first_name ...

DRF: Avoid exposing the API

Utilizing Django in conjunction with Django Rest Framework, I have made the browseable api inaccessible in the settings.py file. Despite this configuration, when I navigate to http://example.com/api - with "example.com" representing my domain - I encounter ...

Exploring the capabilities of Angular and Django Rest Framework applications

Imagine having a front-end application built in React and a back-end application developed using Node.js with Express. The back end has been thoroughly tested with Mocha, and now it's time to create functional tests for the front end. However, since the fr ...

The Axios interceptor is failing to retrieve the user's current authentication token from the Vuex store

Currently, I am utilizing Axios to transmit user input to a DRF API, which then returns an authentication token. This token is being saved in the Vuex store. However, when I attempt to request another API endpoint using Axios with the most recent token in ...

A ModelSerializer that is nested within another ModelSerializer

I'm currently working on setting up a nested JSON file in Django Rest Framework. I've been researching different approaches to properly nest my serializers, but haven't had much success. I'm struggling with creating a model serializer from scratch instead ...

Django REST framework error: 'WSGIRequest' does not contain the attribute 'query_params'

Currently, I am in the process of learning about DRF. One thing I attempted was to print out print request.query_params, but unfortunately encountered an error: print request.query_params AttributeError: 'WSGIRequest' object has no attribute 'query_pa ...

After deploying DRF, the CSS in Django admin is not displaying

After developing a web application using Django Rest Framework and React, I faced an issue during deployment on IIS. While the deployment is successful, I encountered a problem with the Django Admin where the styles were not displaying properly. This led t ...

Is there a way to simply send the data to the API endpoint without having Django allauth url fetching from react and calling the signup view form?

For my project, I am utilizing React as a standalone Single Page Application (SPA) that connects to a Django backend with allauth for authentication management. When I enter the URL on my local browser (192.168.86.28:8000/accounts/signup/ or 127.0.0.1:8000 ...

Using Django Rest Framework (DRF) to transmit an array of images as a

I need assistance with sending an array of images in a JSON format. My desired output is: {"id":1,"timeIntervel":4,"images":["http://127.0.0.1:8000/images/i1.jpg","http://127.0.0.1:8000/images/i2.jpg","http://127.0.0.1:8000/images/i3.jpg","http://127.0.0. ...

Changing Serializer Fields on the Fly in Django Rest Framework

I am attempting to utilize the Advanced serializer method outlined in the Django Rest Framework documentation. in order to dynamically modify a serializer field. Below is my customized serializer class: class FilmSerializer(serializers.ModelSerializer): ...

Is there a way to detect modifications in a JSON API using Django or Android?

I've integrated djangorestframework for my api and am currently developing an Android App that interacts with the api by fetching and posting data. I'm interested in finding a way to detect changes in json data from the api. For example, in a chat applic ...

generate various instances in model serializer generate function

I have created a DRF API View in my Django project to manage Withdraw records. Below is the implementation: class WithdrawListCreateAPIView(PartnerAware, WithdrawQuerySetViewMixin, generics.ListCreateAPIView): permission_classes = (TokenMatchesOASRequi ...

Styles for Django Rest Framework admin interface are not displaying correctly

Has anyone else experienced an issue with the styling in their Django admin panel? The CSS appears to be functioning properly, but once you navigate to a specific model, the layout becomes distorted. I can't seem to figure out what could be causing this ...

Error: Unable to access the 'uname' attribute in the 'os' module within the dockerized environment (docker with Django REST framework)

Hello, I am working with Docker and DRF, and facing some challenges. Initially, I executed this command: pip install -r requirements.txt --use-deprecated=legacy-resolver Below are the contents of my requirements file: asgiref==3.5.2 backports.zoneinfo==0 ...

Nuxt.js encounters difficulties in fetching information from the Django Rest Framework API

I am currently developing a Nuxt.js/Vue frontend for my Django Rest Framework backend. Despite specifying permissions to allow non-authenticated users to read-only, I am having trouble successfully loading data from my API. Index.vue import axios from &a ...

Django Rest Framework encounters issues with processing incorrectly formatted JSON data

My Django Rest Framework function has the following structure: @api_view(['GET', 'PUT']) @permission_classes((permissions.IsAuthenticated,)) def TestView(request, app_id): return Response({}) It is supposed to always generate a JSON response with an em ...

Showing JSON data in a ListView using Django Rest Framework

Looking to showcase JSON data in a ListView on an Android application. Utilizing Django Rest Framework, I have successfully serialized my objects and transformed the information into JSON format which can now be accessed through 127.0.0.1:8000/. Below are ...

What is the best way to send a list of data as either strings or integers through a REST API using Angular's

While trying to post data from Angular formData to a Django REST API, I encountered an error saying "Incorrect type. Expected pk value, received str." Here is how I am currently sending the data using form data: let noticeData = this.announceForm.value; i ...

Django-Rest Framework: Implementing Cursor Pagination for Efficient Data Retrieval

Currently, I am in the process of developing an API using Django-Rest-Framework and I have implemented cursor pagination which is by default ordered by the 'created' filter. This setup has been working well for most of my views. However, I have ...

Determining User Affiliation in Django: Steps to Verify if Users Registered under Me Have New Registrations

Currently, I am working on developing a referral system logic in Django. The referral system is functioning properly at the moment, but I have a new requirement to implement. When I refer both "user 2" and "user 3", the system records that I have referred ...

Errors in implementing custom pagination in Django Rest Framework

In my project, I am utilizing the APIView alongside custom pagination. Although it is functioning properly, I am encountering an issue where the same elements are being displayed multiple times. Below is what I have attempted so far. views.py class Produ ...

Creating multiple objects using POST request with AJAX and Django Rest Framework

I am facing an issue while trying to allow a user to create a new list for a dashboard. The problem arises as follows: User creates the first list: The new list appears once User creates a second list: the second list appears twice User creates a third li ...

Verifying user identity in Django Rest Framework by integrating with Google Authentication

When implementing JWT authentication using username/password, the process goes as follows: from rest_framework_simplejwt.serializers import TokenObtainPairSerializer '''The POST request appears like this: <QueryDict: { 'csrfmiddlewaretoken': ['Pd1 ...

How can the combination of Django and AJAX be utilized most effectively?

Currently, I am tackling my first major project and grappling with the integration of Django with ajax. My website features multiple standalone services written in JavaScript, however there are instances where information needs to be sent to the server. Ad ...

What is the process for assigning an ID to an object by clicking on an adjacent link in Django?

Trying to set an identifier for a CSV file's name so that clicking on a link next to it will lead to viewing the file itself on another webpage. Encountering the error message 'QueryDict' object has no attribute 'objects' Please note: CSV files are colle ...

Evaluating the performance of a Heroku free server under stress conditions

I'm currently working on an Android app that has a backend hosted on a Heroku free server. The current response time for serving requests is 2 seconds. I'm curious to know how many users it can handle simultaneously. I've searched through various Quora qu ...

Error message: Insufficient credentials to access DRF system

For some reason, my app is no longer allowing users to log in after making changes to their profile. I have a nested User serializer with the profile serializer fields (one-to-one relationship) using Djoser for the urls. When attempting to update the user ...

I am currently in the process of cross-referencing the tags that have been retrieved with those that have been selected or created. If a tag does not exist

I have a collection of tags in an object, and I want to dynamically add new tags before submitting the form. Despite using vue watch, it doesn't seem to be working for me. Here is the code snippet: data() { return { blog: { blog_title: ...

The JavaScript fetch API failed to receive a response after sending data via a 'POST' request to a Django server

Currently, I am in the process of developing a poll application that utilizes both Django and React. My approach involves using the fetch API to send POST requests to my Django server and receive detailed information in return for further processing. For a ...

Tips for making axios unique with @nuxtjs/auth-nextTips for modifying axios with @

I've been grappling with this issue for the past three days without any luck in finding a solution. My Nuxt.js frontend relies on the auth module to acquire a JWT token from a DRF backend. Upon logging in, the server returns the following message: Forbidd ...

Creating a time-limited personal link with Django Rest Framework and React

I have a frontend application built with React Framework that I want to provide access to via a time-limited personal link, without the need for additional authentication functions. With approximately 1-2 new users per day, my proposed implementation is as ...

Leveraging foreign key attributes within Angular templates

My technology stack includes Django for the backend with Django Rest Framework and Angular for the frontend. Within the backend, I have defined 2 models: class Post(models.Model): category = models.ForeignKey(Category, on_delete=models.SET_NULL, null= ...