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

11.11.2025
IOS/web Auth Client ID Handling for Google Sign In

To preface, I'm not asking for a direct fix here, I'm just curious if what I'm doing is the appropriate auth flow for setting dynamic client ID based on device platform. I am 2 applications that use the same Django …

11.11.2025
Flaky Circle CI tests (django): ImportError: cannot import name "task" from "app.tasks" (unknown location)

Sometimes, I have many flaky test failures due to one error: ImportError: cannot import name 'task_import_events_to_db' from 'app.tasks' (unknown location) It seems the tests fail because of this import error. Meanwhile, other branches pass without issues, and tests …

10.11.2025
KeyError 'email' for django-authtools UserCreationForm

I am experiencing an error for which I can’t find an origin. I believe the error stems from GitHub - fusionbox/django-authtools: A custom User model for everybody!, and disclaimer, I have asked this same question on the …

10.11.2025
Django check at runtime if code is executed under "runserver command" or not

I've a project based on django that wrap some custom code, this code during import load some heavy file before to be executed. I need to check if imports are executed under "runserver command" or not, in this way I …

10.11.2025
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.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', …

10.11.2025
Cannot query "admin": Must be "ChatMessage" instance in Django

In View Function it can show this error Request Method:GETRequest URL:http://127.0.0.1:8000/inbox/Django Version:4.2.25Exception Type:ValueErrorException Value:Cannot query "admin": Must be "ChatMessage" instance.Exception Location:D:\Socialmedia\.venv\lib\site-packages\django\db\models\sql\query.py, line 1253, in check_query_object_typeRaised during:core.views.messages.inboxPython Executable:D:\Socialmedia\.venv\Scripts\python.exePython Version:3.9.13Python Path:['D:\\Socialmedia', 'C:\\Users\\ER-RPJ\\AppData\\Local\\Programs\\Python\\Python39\\python39.zip', 'C:\\Users\\ER-RPJ\\AppData\\Local\\Programs\\Python\\Python39\\DLLs', 'C:\\Users\\ER-RPJ\\AppData\\Local\\Programs\\Python\\Python39\\lib', 'C:\\Users\\ER-RPJ\\AppData\\Local\\Programs\\Python\\Python39', 'D:\\Socialmedia\\.venv', 'D:\\Socialmedia\\.venv\\lib\\site-packages'] def inbox(request): …

10.11.2025
Is it reasonable to use Cloud storage for async webhook processing on Cloud Run

I'm processing webhooks on Cloud Run (Django) that need async handling because processing takes 30+ seconds but the webhook provider times out at 30s. Since Cloud Run is stateless and spins up per-request (no persistent background workers like Celery), I'm …

09.11.2025
Django ORM: Add integer days to a DateField to annotate next_service and filter it (PostgreSQL)

I am trying to annotate a queryset with next_service = last_service + verification_periodicity_in_days and then filter by that date. I am on Django 5.2.6 with PostgreSQL. last_service is a DateField. verification_periodicity lives on a related SubCategory and is the number …

09.11.2025
Stuck with django asgi server (dpahne) and aws eb (with docker)

I’m trying to deploy a Django application that uses Channels + ASGI + Daphne on AWS Elastic Beanstalk with the Docker platform. My container builds successfully, migrations run, and Daphne starts properly on 0.0.0.0:8000. Logs show the ASGI server is …

09.11.2025
Unable to access my EC2 ubuntu server with public ip:8000 [closed]

I associated public elastic ip address to my EC2 instance , Installed Virtual environment properly, python manage.py runserver 0.0.0.0:8000 is executed properly Postgresql is connected at port 5432 properly. Port 22, 80, 443 firewall are allowed properly here is the …

09.11.2025
Django Not Saving Form Data

I fill the Django form in contact.html file. But form data is not saved in database or another place. There is no error or warning while saving the form data. Form screenshot: Form screenshot. views.py: from .forms …

08.11.2025
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 api-token-auth/ endpoint. Context I am sending …

07.11.2025
'django.db.utils.ProgrammingError: relation "users_user" does not exist' error while running ' python manage.py migrate_schemas --shared'

AccrediDoc - Multi-tenant Accreditation Management System A comprehensive Django-based multi-tenant accreditation management system designed for healthcare organizations in India. Manage NABL, NABH, ISO 15189 and other healthcare accreditations with ease. Features Multi-tenant Architecture: Secure, isolated environments for multiple organizations …

07.11.2025
Django: Annotate queryset based on the existence of many-to-many relationships

I am using Django 5.2 with Postgres 17 and try to modify the queryset of a ListView for row-based access control. Items are to be included in the queryset either if the user is part of a project that is …

07.11.2025
Django views spawn the error "cleansed = [self.cleanse_setting("", v) for v in value]" and go in infinite loops

I have two views that spawn these messages in "sudo systemctl status gunicorn": gunicorn: Nov 07 10:46:36 mysite gunicorn[2107]: cleansed = [self.cleanse_setting("", v) for v in value] Nov 07 10:46:36 mysite gunicorn[2107]: File "/home/mysite/anaconda3/envs/mysite/lib/python3.10/site-packages/django/views/debug.py", line 135, in cleanse_setting The …

07.11.2025
AppAccountToken not sent to backend during Apple coupon (reward) redemption using StoreKit 2

I'm integrating Apple In-App Purchases with StoreKit 2 in an iOS app. The backend (Django) handles subscription verification and links each transaction to a user using appAccountToken. Everything works fine for normal subscription purchases — the app sets the …

06.11.2025
Upgrading Django to 5.2.7 causing error wth rest_framework_simplejwt as django.utils.timezone is depreciated

I am upgrading my Django project to v5.2.7. After installing requirements.txt with the upgraded versions of all libraries, I ran the command to validate the code python manage.py check But it is throwing error ImportError: Could not import 'rest_framework_simplejwt.authentication.JWTAuthentication' for …

06.11.2025
Error running developmental server in Django project some issue with migration

I have developed a project for SASS with django tenate. While migratiing, I got the following error it seems, like it is related to migration file. (acc_venv) D:\\workik_projects\\AccrediDoc_v2\>py manage.py makemigrations report Traceback (most recent call last): File "D:\\workik_projects\\AccrediDoc_v2\\manage.py", …

05.11.2025
Django static images not showing on Vercel

I'm deploying my Django project to Vercel, and everything works fine locally but after deployment, images from the static folder are not showing. Project structure: datafam/ ├── settings.py ├── wsgi.py static/ └── teams/ └── image/ ├── Abu Sofian.webp ├── Crystal …

05.11.2025
"SMTPAuthenticationError: Authentication disabled due to threshold limitation" on production server on AWS

I've set-up email sending in my Django project that is deployed on AWS. When I run it locally the emails go out without a problem, but when I try it on production server on EC2 ubuntu VM, I get smtplib.SMTPAuthenticationError: …

04.11.2025
Cloud Storage + Cloud Tasks for async webhook processing on Cloud Run - best practice

I've been looking around for an answer to this, but struggling to find something definitive. My apologies if I've overlooked something obvious. I'm processing webhooks on Cloud Run (Django) that need async handling because processing takes 30+ seconds but the …

03.11.2025
How do you customise these 3 dots in wagtail?

I want to add another option in it which is send Email, which will send email to all the subscribers class FeaturedPageViewSet(SnippetViewSet): model = FeaturedPages menu_label = "Featured Pages" menu_icon = "grip" menu_order = 290 add_to_settings_menu = False exclude_from_explorer = …

03.11.2025
Django app static files recently started returning 404s, deployed by Heroku

The static files in my Django production app recently started returning 404s. Screenshot of production site with dev tools open Context This project has been deployed without issue for several years. I have not pushed …

03.11.2025
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 have assigned him no permissions. Yet he …

03.11.2025
Django gunicorn gevent with Statsig - run code in forked process

I am running Django app with gunicorn gevent workers. I'm using Statsig for Feature Flagging. It appears to be struggling, I assume due to gevents monkey patching. I was hoping I could get around this by running Statsig post app …

02.11.2025
Django Materialized View Refreshing Celery Task is freezing in DB layer for larger dataset

In my application, written in Django 5.2, I want to aggregate static data and store it as a materialized view in PostgreSQL 16.10. I can create it as my own migration or using the django-materialized-view library. I have no problems …

01.11.2025
Django unicorn asgi concurrency performan issue

We are running Django with uvicorn asgi in kubernetes. Following best practice guides we are doing this with only 1 worker, and allowing the cluster to scale our pods up/down. We chose asgi as we wanted to be async ready, …

31.10.2025
Create question with options from same endpoint

So i am making a backend system using DRF in Django, this is my first project in django and drj, i am using django purely as a rest backend i am making a Quiz/mcq application this is from my questions …

31.10.2025
Django difference between aware datetimes across DST

I'm working on a Django application in which I need to calculate the difference between timestamps stored in the DB. This week I run into some problems related to DST. In particular in the following code snippet: tEndUtc = tEnd.astimezone(timezone.utc) …

31.10.2025
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 …

31.10.2025
Django Celery Beat SQS slow scheduling

Beat seems to be sending the messages into SQS very slowly, about 100/minute. Every Sunday I have a sendout to about 16k users, and they're all booked for 6.30pm. Beat starts picking it up at the expected time, and I …

30.10.2025
Django Mongodb Backend not creating collections and indexes

Summary Running Django migrations against our MongoDB database does not create MongoDB collections or indexes as defined in our app. The command completes without errors, but no collections or indexes are provisioned in MongoDB. Environment Django: 5.2.5 django-mongodb-backend: 5.2.2 Python: …

30.10.2025
How to aggregate hierarchical data efficiently in Django without causing N+1 queries?

I’m working with a hierarchical model structure in Django, where each level can represent a region, district, or village. The structure looks like this: class Location(models.Model): name = models.CharField(max_length=255) parent = models.ForeignKey( 'self', on_delete=models.CASCADE, related_name='children', null=True, blank=True ) def __str__(self): …

29.10.2025
Deploy Django and Nginx under subpath

I'm trying to deploy a Django app with Gunicorn and Nginx under a subpath, I'm inside a corporate network, and the path www.example.com/myapp points to the IP 192.168.192.77:8080 of my PC on the local network (I have no control over …

29.10.2025
Django transaction.atomic() on single operation prevents race conditions?

Why I need to use atomic() when I have only 1 db operation inside atomic block? My AI-assistant tells me that it prevents race conditions, but I don't use select_for_update() inside. It tells that db looks on unique constraints and …

29.10.2025
Can't find xgettext or msguniq but gettext-base is installed

As part of a django project, I need to build translation *.po files, but I have the error CommandError: Can't find xgettext. Make sure you have GNU gettext tools 0.19 or newer installed. when I run django-admin makemessages -a …

28.10.2025
Encoding full payload and decoding in server in REST

Issue 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, which will just be stored in …

27.10.2025
Deploying Dockerized (React + Django + PostgreSQL ) app with custom license to a client without exposing source code

I am running a test simulation on a virtual server in VirtualBox to see how the procedure of installing a web application using Docker would work on a client server. My stack includes: Frontend: React.js, built into a Docker …

25.10.2025
How to Avoid JWT Collision While Receiving Bearer Token

I am doing a Django project where I am using JWT token for authentication. But the problem is that two different JWT tokens are both valid with the same signature that is provided in the backend with …

25.10.2025
Can't insert rows into Supabase profile table even after creating the RLS policy to do so for the sign up feature

Again, I am quite new to Supabase so I apologize in advance if I don't provide clear details in this post or mess up with some terms or something Basically, I am doing auth using Supabase and have this table …