31,717 questions
-3
votes
2
answers
70
views
Python Django Rest Framework [closed]
what is the difference between decorator @api_view and @csrf_exempt in project level django rest framework? I need the difference and which is better to develop the project.
2
votes
2
answers
55
views
Django REST project doesn’t detect apps inside the “apps” directory when running makemigrations
I have a Django REST project where I created a directory called apps to store all my apps.
Each app is added to the INSTALLED_APPS list in my settings file like this:
INSTALLED_APPS = [
'django....
1
vote
1
answer
56
views
403 Forbidden: "CSRF Failed: CSRF token missing." on DRF api-token-auth/ after applying csrf_exempt
I'm encountering a persistent 403 Forbidden error with the detail:
CSRF Failed: CSRF token missing.
This happens when trying to obtain an authentication token using Django REST Framework's built-in ...
2
votes
2
answers
49
views
Django Rest Framework ListAPIView user permissions - Cant seem to get them working
I have a Django project with DjangoRestFramework. I have a simple view, Facility, which is a ListAPIView. Permissions were generated for add, change, delete and view.
I have create a new user, and ...
0
votes
1
answer
62
views
Create question with options from same endpoint
I am making a back-end system using DRF in Django. This is my first project in Django and DRF. I am using Django purely as a REST back-end
I am making a quiz/mcq application
This is from my questions ...
4
votes
1
answer
100
views
can I use get_or_create() in django to assign a global variable?
I am an intern at a company and we are using django as framework.
I was working on a two part register system in which an admin performs the initial registration after which a link is sent to the user ...
-2
votes
0
answers
71
views
Encoding full payload and decoding in server in REST
WAF is showing some errors due to including some HTML tags in my payload responses (mostly field-like messages and user guides). Sometimes, I am also sending R programming language code to the server, ...
0
votes
1
answer
55
views
Django Generics custom quering
I was working on notion like app, so I have a Note(consider as a Page in notion) and in that i am having blocks, where block having different id's and held with Note in Foreign field so now in views ...
0
votes
0
answers
58
views
Django Testing in microservices with more than 1 db running
I would like to ask about a certain topic that is tough one. Im working in a project that has microservices architecture with more than 1 databases running every time. in django, how can I perform ...
0
votes
1
answer
60
views
My django API “next” link uses a stale hostname only when receiving requests from GKE services (Like Cloud Run)
What are the details of your problem?
I have a application in Django that is deployed using GKE. It uses an ingress to deploy it...
Those manifests.yml that are used for deploying applications on ...
0
votes
1
answer
148
views
POST requests from Cloud Run arriving as GET requests in my Django REST API
I have a serverless pipeline on Google Cloud. It consists of three total steps:
A video uploader that sends videos to Google Cloud Storage. Working fine.
An eventarc + pub/sub trigger that fires ...
1
vote
0
answers
38
views
Django timestamp__date filtering works locally but returns extra rows in production?
I have a Django API that returns self signedup users in a given date range. The AuditLog model stores timestamp with DateTimeField(default=timezone.now) and USE_TZ=True.
Locally, the date filter works ...
0
votes
0
answers
76
views
StreamingHttpResponse being buffered when using uvicorn/gunicorn/daphne in Django
I have a very simple view that Streams a repsonse. When using python manage.py runserverthe stream works as expected. But, when we use uvicorn app.asgi:application or daphne app.asgi:application or ...
1
vote
0
answers
90
views
How to use DRF serializer fields as django-filter filter fields?
I’m working with Django REST Framework and django-filter to implement API filtering.
I created custom serializer fields (for example, a JalaliDateField that converts between Jalali and Gregorian dates,...
0
votes
1
answer
125
views
dj-rest-auth + allauth not sending email
Context: I'm setting DRF + dj-rest-auth + allauth + simple-jwt for user authentication.
Desired behaviour: Register with no username, only email. Authorize login only if email is verified with a link ...
0
votes
0
answers
37
views
Using Django jwt tokens with Nextjs with cookies
My backend has an endpoint: /auth/jwt/create that returns a JSON response containing the access and refresh tokens. With my current backend setup, I send the tokens in both the response body and in ...
0
votes
2
answers
175
views
How to secure a refresh token in a JWT system when it's sent as an httpOnly cookie
In my React + Django project, I’m currently sending the refresh token as an HttpOnly cookie. The problem with HttpOnly cookies is that they are automatically sent by the browser, which makes them ...
0
votes
1
answer
118
views
Django REST Framework: "No default throttle rate set for 'signup' scope" even though scope is defined
I’m trying to apply custom throttling for the signup endpoint in my Django REST Framework API. The goal is to allow only 5 signup attempts per hour for anonymous users. I created a SignupRateThrottle ...
0
votes
1
answer
132
views
Django REST framework gives me csrf token missing when i am logged in for POST requests
i am making an API with django rest framework and django 5.2
when i send a POST request, if i be logged in it gives me an CSRF token missing error.
but if i be logged out it gives me response with no ...
0
votes
2
answers
199
views
Managing Django groups and permissions for custom users
For my Django projects, I am used to creating a custom user model and managing what my user can do for a specific route using a roles field like this:
class User(AbstractBaseUser, PermissionsMixin):
...
0
votes
1
answer
86
views
Django REST API endpoints URL paths
I have a Django 4.2 app with Postgres DB and REST API. My urls.py contains this path in urlpatterns:
path('create/<int:pk>/<str:name>/', ComponentCreate.as_view(), name='create-component')
...
1
vote
2
answers
97
views
How to handle customer.subscription.created if a organization(tenant) doesn’t exist yet in Stripe webhook?
I'm using Django and Stripe for a multi-tenant SaaS. I register users and organizations manually from a view, and I create the customer and subscription using Stripe API before saving to the database.
...
1
vote
0
answers
59
views
unit testing in DRF, Error mock.patch transaction.atomic with unittest.mock.patch
@transaction.atomic
def deposit(user: User, account_number: str, amount: float) -> None:
account = get_object_or_404(
Account.objects.select_for_update(), account_number=account_number, ...
-1
votes
1
answer
79
views
React and Django DRF [closed]
The backend works, when i test it with an http file. and directly at the endpoint.
POST http://localhost:8000/api/products/ HTTP/1.1
Content-Type: application/json
Authorization: Bearer ...
0
votes
2
answers
142
views
Refresh token being passed in response body in registration but not login in Django
I am using the Django REST Framework with dj-rest-auth and django-allauth for authentication and authorisation with JWTs. From what I have heard, using HTTP-only cookies to store the tokens is a ...
0
votes
0
answers
114
views
Django Rest viewsets.ModelViewSet form view dynamic update choices list field from other field change
file models.py
ANIMATIONS_ACTIONS = (
('0', _('Stop animations')),
('1', _('Start animations')),
('2', _('Restart animations')),
('3', _('Suspend animations')),
('4', _('Unload ...
0
votes
1
answer
72
views
Django REST Framework `pagination_class` on ViewSet is ignored
Describe the Problem
I have a ModelViewSet in Django REST Framework designed to return a list of Order objects. To improve performance, I'm trying to implement custom pagination that limits the ...
1
vote
2
answers
75
views
how DRF undestand which field in serialazer.py is related to which model field?
imagine i have a super simple serializer.py file :
and i just want to use it ! nothing special ..
so im going to write something like this (with a model class called "Product") & its ...
2
votes
1
answer
40
views
source is not working for deserializing POST data in django rest framework
The following example doesn't work as expected, and returns a validation error. Why is that?
from rest_framework import serializers
class TestSerializer(serializers.Serializer):
from_field = ...
1
vote
1
answer
36
views
need to combine an enum and a timesstamp in DRF
Django Admin: How to combine archived_at and archive_status into one archival source?
I’m building a feature to archive users via Django Admin. Currently, I’m using both a DateTimeField (archived_at) ...
1
vote
1
answer
34
views
DRF I need object/instance-level premissions granted but view/model-level permissions denied
I have a rather simple backend and API with two user types, User and Admin. I have created groups and permissions in Django. The Admin should CRUD everything and the User should only view and edit ...
1
vote
2
answers
141
views
How to use CustomUser with dj_rest_auth to sign up with email and password
How to use CustomUser with dj_rest_auth to register with email and password.
I have the source code below, but the username information is required during the sign-up process.
I would like to know how ...
1
vote
1
answer
53
views
Slug is not created correctly due to using django parler
I have a problem creating a slug based on the title and pk, due to the use of parler.
I'm using Parler for multilinguality in my API, and when I try to create a slug like
title-pk I'm getting various ...
1
vote
1
answer
70
views
How to support multiple Google Cloud Storage buckets in a Django FileField without breaking .url resolution?
I'm using Django with django-storages and GoogleCloudStorage backend.
My model has a FileField like this:
raw_file_gcp = models.FileField(storage=GoogleCloudStorage(bucket_name='videos-raw'))
At ...
0
votes
1
answer
63
views
How do I log filtered GET requests on a Django REST Framework ModelViewSet using @action?
I have a ModelViewSet for EventReportLink and need to log every time someone queries with ?event_report__id=<id>. I’ve tried adding a custom @action(detail=False, methods=['get']), but I’m not ...
0
votes
1
answer
52
views
How to make DRF use url path as empty and base path?
I am trying to omit the URL path for an action in a ViewSet like
@action(detail=False, methods=['patch'], url_path='')
def update_current_user(self, request):
But when I give url_path as an empty ...
1
vote
1
answer
64
views
Elasticsearch search only by one field
I have app on drf and i added elasticsearch(django_elasticsearch_dsl) for searching. But i faced with problem, when i want to search on two or more fields, elastic searching only by one field.
I'm ...
1
vote
1
answer
88
views
React doesn’t receive API tokens after Google OAuth redirect via social_django/drf-social-oauth2
I'm implementing Google OAuth2 for my Django REST API with a React frontend. The basic flow is set up correctly.
I have routes for:
urlpatterns = [
path("admin/", admin.site.urls),
...
0
votes
1
answer
70
views
CSRF token not set
I was creating my api using django restframework. I am using simple jwt for authentication. The tokens are generated after user login via his/her email and password but before login email must be ...
3
votes
3
answers
46
views
DRF Delete API Method Get Error instead of delete
I'm trying to delete a Classroom object from the database. When I try to go to Django Rest Web Browser to fetch api/classroom/delete/1/ I get this response.
HTTP 405 Method Not Allowed
Allow: DELETE, ...
0
votes
1
answer
63
views
How should I define redirect request properly
I have a social network project for users to share their recipes. The Recipe objects managed by a ViewSet, which has Serializer, where create and update recipes operations defined, via POST and PATCH ...
0
votes
1
answer
35
views
How to efficiently combine Redis-based recommendation scoring with Django QuerySet for paginated feeds?
I'm building a marketplace app (think classified ads with negotiations) and trying to implement a personalized recommendation feed. I have a hybrid architecture question about the best way to handle ...
1
vote
2
answers
612
views
django-allauth W001: ACCOUNT_LOGIN_METHODS conflicts with ACCOUNT_SIGNUP_FIELDS with Custom User Model (email as USERNAME_FIELD)
I'm working on a Django project using django-allauth and dj-rest-auth for authentication. I've set up a custom user model (CustomUser) where email is the USERNAME_FIELD and username is set to None.
I'...
1
vote
2
answers
110
views
ModelViewSet does not overwrite DEFAULT_PERMISSION_CLASSES'
Hello I'm working on making all urls requires user to be authenticate , but some urls i want them to be accessible by public, so i use permission_classes = [AllowAny] and authentication_classes = (...
0
votes
2
answers
102
views
Django Rest Framework Cursos pagination with multiple ordering fields and filters
I have an issue with DRF, CursorPagination and Filters.
I have an endpoint. When I access the initial page of the enpoint I get a next URL
"next": "http://my-url/api/my-endpoint/?cursor=...
2
votes
1
answer
47
views
Do I need to serialize permissions in django rest framework
I'm using DRF and NextJS(app router) to build an application with a search feature that saves the authenticated user's search history. The search history is their search terms with a timestamp and ...
1
vote
0
answers
68
views
How can I download a file?
could someone explain to me how to download a file that I saved on the local disk with this function? This from React.
Also i'm using Django Rest Framework
in my file utils.py from I have this ...
1
vote
1
answer
48
views
Do you see any circular imports
I am getting this error with DRF, django.core.exceptions.ImproperlyConfigured: The included URLconf and I can not find the cause of it. My urls.py is afaiK configured correctly, so I'm looking for ...
0
votes
2
answers
57
views
Using the Django REST Framework, how can I set a field to be excluded from one view, but included in an other, without much bloat code?
For example, if I had these models, how can I make sure that only the name of the house is displayed in one view, and all of it's properties are displayed in an other. Also, how can I display the ...
0
votes
0
answers
69
views
Vehicle records for auto parts application
I'm trying to figure out how to create a vehicle filter for an auto parts application for a client. They want their customers to be able to filter by Year, Make, Model, Trim and Engine.
We're using ...