"Вопросы и ответы" Django и Python

30.06.2025
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 sure if I’m implementing it correctly or if there’s a better way. I added: …

30.06.2025
How to remove hardcoded library version info from minified JS files in Django production?

'm using Django to serve static files in production, and I've noticed that many of the third-party JS libraries (like jQuery, Bootstrap, JSZip, and Moment.js) include hardcoded version numbers inside the minified files. For example: /*! jQuery v3.3.1 */ "version": …

30.06.2025
Медленно работает форма Django

Создал форму через forms.ModelForm в django, на форме есть выпадающий список с очень большой выборкой из таблицы (список производителей запчастей, foreign key). Форма очень медленно работает, можно ли как-то это оптимизировать? В админской панели есть autocomplete, а как его на …

29.06.2025
How to integrate ZKTeco ZK4500 fingerprint scanner with a Django + React web application? [closed]

I'm working on a web application using Django (backend) and React (frontend), and I want to integrate the ZKTeco ZK4500 fingerprint scanner into my system for user authentication. 🔍 My Setup: Device: ZKTeco ZK4500 (USB fingerprint scanner) Backend: Django …

29.06.2025
Filter some data in one column in table

In a Django project, I want to display values from a table in the database, provided that a filter is applied to some data in one of the columns. For example, the gender column. I want to display only female …

28.06.2025
How to handle constraint errors like unique or not null from DB in Django

I have a write operation which adds a record in rider model. The rider_code is unique in this. Now 1 way is to first check if any record with that rider_code exists then return error else create rider. But it …

27.06.2025
Django application deployement with Docker

I am trying to deploy my django app with docker. But when it come to excute my script to be sure that the databse (postgres) is ready, I allways get this error : chmod: /app/scripts/wait-for-it.sh: Permission denied and then the …

27.06.2025
Celery is not running despite correct configuration - using Django, Celery 5+, and Python 3.12+

Despite what appears to be a correct initial configuration, Celery tasks are not running. The logging system does not show any errors. This is a new setup of Celery version 5+ running on Python 3.12+. Full server-side configuration has been …

27.06.2025
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 string, DRF defaults to the function name and looks for …

27.06.2025
ImportError: Module "django_comments_xtd" does not define a "XtdComment" attribute/class

When I installed django-comments-xtd according the documention I got this error: ImportError: Module "django_comments_xtd" does not define a "XtdComment" attribute/class Configs in settings.py are: INSTALLED_APPS += [ 'django_comments_xtd', 'django_comments', 'django.contrib.sites', ] SITE_ID = 1 COMMENTS_APP = …

26.06.2025
Django forloop in template

Forloop is overriding the other, how do I use two different forloop in one template without interrupting each other. The 'include template" do not display its contents if 'for users in all_users' is the parents. How do I make 'for …

26.06.2025
ERROR: Failed to build installable wheels for some pyproject.toml based projects (mysqlclient)

Building wheel for mysqlclient (pyproject.toml) ... error error: subprocess-exited-with-error × Building wheel for mysqlclient (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [91 lines of output] C:\Users\Acer\AppData\Local\Temp\pip-build-env-qm2za2yg\overlay\Lib\site-packages\setuptools\config_apply_pyprojecttoml.py:82: SetuptoolsDeprecationWarning: project.license as a TOML table is deprecated !! ******************************************************************************** …

26.06.2025
How can I filter values ​from one model and insert the result into the form as choices?

Good day! I have two tables - models. I fill them gradually. First I have the first table. First I enter data into the first table. And there - in the first table I have - repeating data. Field - …

26.06.2025
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 trying to search by both 'title' and …

26.06.2025
Add new input field to Django form

I am working on a signup form within a Django project. I have the following: <div class="form-row"> <div class="col-md-6"> <div class="form-group"> <label class="large mb-1">First Name</label> {{ form.first_name }} </div> </div> <div class="col-md-6"> <div class="form-group"> <label class="large mb-1">Last Name</label> …

25.06.2025
Why are we seeing incorrect timings in Datadog APM tracing for simple actions like a Redis GET?

We have Python Django application deployed to AWS EKS on EC2 instances. We use Gunicorn as our web server, although we recently ran Apache + wsgi and saw the same issues. The EC2 instances are m6a.xlarges, the containers themselves have …

25.06.2025
Deploying Django + xlwings library

I'm trying to deploy a Django app which uses the xlwings dependency (windows only) on a server. Tried on Linux, but it does not support xlwings. So, now looking out for an easy way to set up the Deployment with …

25.06.2025
How can I create a table or form with the addition of values from another table based on the selected values?

Good day! I have several model tables. And each subsequent table in the conditional hierarchy is one step lower than the previous one. I have one model that is planned to be filled from the form in the database. And …

25.06.2025
Can I use my DjangoCMS template in my AppHook application?

Context: I am trying to integrate an application in my djangocms website. As i want it seems totally integrated, i want my appHooked application to use the same template as my main DjangoCMS template (I am using an extends of …

25.06.2025
Cloudinary image upload isssu with python, Django and DRF

I am trying to upload my produts image to cloudinay, I setting all thing correctly adding middleware but always my image saevd in locally

25.06.2025
How to update removed model choices in Django without breaking existing database values?

I'm working on a Django project where we use models.TextChoices for fields like current_status. Our client requested wording updates — for example, renaming "Contacted" to "Contacted for assessment", "Booked" to "Assessment booked", and so on. Previous Enum: class …

24.06.2025
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), path("api/v1/", include((v1_patterns, "v1"))), path("api/v1/auth/", include("social_django.urls", namespace="social")), path("api/v1/auth/token/", include("drf_social_oauth2.urls", namespace="oauth2")), …

24.06.2025
How can I load values ​into the form from the desired table row by clicking?

Good day! I plan to build a mini application. Which consists of one page (the main one) - a template. And also one secondary page - on the second page I fill in information into the model table through a …

24.06.2025
How to display a friend request button on each post?

I'm trying to make each post from all users have a friend request button for each specific user who uploaded post on homepage. This code below is what I have tried but friend request button is not displayed on each …

24.06.2025
I have this while running django [closed]

Error faced (venv) PS C:\Users\Personal\Desktop\Onblu_VW1_API\api_vw1> python manage.py makemigrations Traceback (most recent call last): File "C:\Users\Personal\Desktop\Onblu_VW1_API\api_vw1\manage.py", line 22, in <module> main() File "C:\Users\Personal\Desktop\Onblu_VW1_API\api_vw1\manage.py", line 18, in main execute_from_command_line(sys.argv) File "C:\Users\Personal\Desktop\Onblu_VW1_API\venv\Lib\site-packages\django\core\management\__init__.py", line 442, in execute_from_command_line utility.execute() File "C:\Users\Personal\Desktop\Onblu_VW1_API\venv\Lib\site-packages\django\core\management\__init__.py", line 416, in execute …

24.06.2025
How to send OTP to Gmail using Django Rest Framework?

I'm trying to implement an OTP verification system using Django Rest Framework (DRF). The goal is to send a 6-digit OTP to the user's Gmail address during registration or login. Here's what I've done so far: Generated a random 6-digit …

23.06.2025
How to pass pk to form (ForeignKey) and views - from template when following link?

How to pass pk to the form (ForeignKey) and views - from the template when clicking on a link? Good day! I have a model. Which is displayed in the template. And the transition to another template is configured by …

23.06.2025
Best practice to create a django user connected to a stripe customer

I'm trying to create a simple website for selling a digital good. Frontend is html/js, backend is django (using allauth, with simple email registration and a Custom User model) and I'm using stripe to handle payments. I've implemented a checkout …

23.06.2025
Routing Problem from sign in page to a users account

The Issues is routing a user after creating an account on the webapp platform to the users dashboard created for the user. I can provide with the sign in and authcontext.js page which helps with this. signin.js import React, { …

23.06.2025
Can users and superusers have the same email/username in a Django application?

I have a CustomUser class for my users which is as follows. class CustomUser(AbstractBaseUser, PermissionsMixin): username = models.CharField(max_length=150, unique=True, null=True, blank=True) email = models.EmailField(max_length=240, unique=True) first_name = models.CharField(max_length=30, blank=True) last_name = models.CharField(max_length=30, blank=True) is_active = models.BooleanField(default=True) is_staff = models.BooleanField(default=False) is_superuser …

23.06.2025
Indexing multiply nested models with django_elasticsearch_dsl

I'm trying to use Elasticsearch in my Django app. I have Lemma models that can have multiple Forms with one citation form that can, in turn, have multiple Spellings. I'm trying to execute a search on (1) the Lemma's citation …

22.06.2025
In django which logout option is best - custom logout or LogoutView? [duplicate]

Actually i'm using django 5.2.3 in that version LogoutView is always gives error. Any other way is there for LogoutView because i try all the way?............................................................................................................................................

22.06.2025
How can I make GrapesJS pages dynamic with real-time data from a Django backend in a React app?

I’m building a page builder application using GrapesJS, React, and Django (as the backend). I’ve successfully integrated GrapesJS into the React frontend, and I can design and save pages. However, I’m struggling to figure out how to make the created …

21.06.2025
Django static files not loading for one app when DEBUG=False [duplicate]

I'm working on a Django project with multiple apps (Home, student, login, etc.). When I set DEBUG = False in settings.py, the static files (CSS and JS) from my Home app load fine, but the static files from the student …

21.06.2025
How to change django default files storage to cloudinary storage for media files?

I am working on django project. It is working fine with local storage and decided to use cloudinary for media storage then for some reason the file storage is not changing to cloudinary media storage. Here's my settings.py file: <pre …

21.06.2025
Django - S3: collectstatic does not create new folder, even with all permissions and write privileges

Cursor ai called it a &quot;strange problem&quot;, so we're back to the original home of solutions. I upgraded django from 2.2 to 5.2, and upgraded my storages, tinymce,.. etc modules along with it. STORAGES = { 'staticfiles': { 'BACKEND': 'storages.backends.s3boto3.S3Boto3Storage', …

20.06.2025
Performance Degradation & Timeouts Since Django & Stack Upgrades

We’ve been experiencing significant performance issues and intermittent timeouts on our app ever since we upgraded: Django from v2.x to v4.2 Heroku stack from 20 to 22 Prior to these upgrades, our response times were solid and timeouts …

20.06.2025
Integrating New Google Maps Autocomplete API into Django Project

I'm using the new Google PlaceAutocompleteElement() API function (not the legacy google.maps.places.Autocomplete) and would like help integrating it into my Django project. Specifically, I want to add an address search bar to my application.html template. I've tried connecting the initMap() …

20.06.2025
Celery healthcheck fails in `set -e; cmd1;cmd2` and functions in `set -e; cmd1 && cmd2`

Problem docker compose fails app container for django celery app only in one of the 4 potential use cases. In each of the cases, the script in question is running inside the same django python docker image. The HOST OS …

20.06.2025
Node npm error - could not determine executable to run

I was trying to install tailwind css using npm on my python django project in vscode, and for some reason kept running into the following error messages: npm ERR! could not determine executable to run So then i tried it …