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

10.07.2025
Django-celery-results: error ModuleNotFoundError: No module named 'django_celery_results'

I try to run "celery -A myproj worker -l info" and it gives me the error ModuleNotFoundError: No module named 'django_celery_results'. All dependencies are installed (django, celery, django-celery-results, redis). I tried to run it with admin rights, but it didn't …

10.07.2025
How to store the refresh token in HttpOnly cookie with Google OAuth2 (PKCE flow) in Django?

I'm using Django with drf_social_oauth2 and oauth2_provider for Google OAuth2 authentication. I’ve successfully implemented the PKCE authorization flow. Step 1: Frontend redirects to: GET /api/v1/o/authorize/?client_id=<client_id>&response_type=code&redirect_uri=http://127.0.0.1:5173/callback&code_challenge=<challenge>&code_challenge_method=S256 Step 2: Frontend exchanges code at: POST /api/v1/o/token/. Backend responds with: { "access_token": …

10.07.2025
Celery chord callback executes before tasks completes

I have a celery workflow, as presented in the above image. I am facing a scenario where the parent_task_callback is executed before all the sub_parent_task callbacks are executed. …

10.07.2025
How to handle error reporting and validation of uploaded files using django-formset?

Short version I'm using django-formset to create a contact form that includes a file upload field. When an incorrect file is selected, no error message is shown. When uploading the form with an incorrect file, the field is cleared and …

09.07.2025
UnicodeDecodeError when connecting to PostgreSQL using psycopg2, despite UTF-8 encoding everywhere

I'm trying to connect to a local PostgreSQL database using psycopg2 in Python. Here's the code I'm using: import psycopg2 params = { 'dbname': 'database_name', 'user': 'user_name', 'password': 'mypassword', 'host': 'localhost', } for k, v in params.items(): print(f"{k}: {v} (type={type(v)}, …

09.07.2025
Seeking a Clear Roadmap for Learning Python and PHP as a Junior Developer (with Remote Work Goals) [closed]

Seeking a Clear Roadmap for Learning Python and PHP as a Junior Developer (with Remote Work Goals) Body: Hello everyone, I’m a junior developer currently learning both Python and PHP, and I find myself a bit confused about which …

09.07.2025
How can I create a grouped set of elements for Grouped Radio Buttons

How can I create a set of elements to place in views? GROUPED_CHOICES I have a list of elements. zzz = [m1-x, m2-x] - the number of repetitions of each group name - the number of elements to group xxx …

09.07.2025
How to get mutual followers (mutual friend) for users - Django

How do I get mutual followers (friends of friends) with request.user to be displayed for each users posts, I was able to display the count for mutual followers for each users posts on newsfeed. How can I get it done? …

09.07.2025
How can I insert additional text elements through a loop into the set of choices form elements in the template?

How can I move the iterable value (radio) from the outer loop to the inner one, bypassing the inner loop iteration? How can I get the value (radio) of the outer loop. I have a nested loop that generates additional …

09.07.2025
Job hunting advice for a self-taught dev feeling stuck [closed]

I'm a self-taught full-stack web developer. I've been learning and building projects for about a year now using technologies like Python (Django) and React.js. Now that I feel somewhat confident with my skills, I think it's time to start looking …

08.07.2025
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 itself. I've used DjangoModelPermissions …

08.07.2025
Django PWA offline template not showing

Why my django pwa offline template is not showing i checked everthing is in its position and also there is to typo mistakes my offline.html is in write path templates/patients/offline.html and i also added PWA_APP_OFFLINE_TEMPLATE = 'patients/offline.html' in my settings.py …

08.07.2025
How can I move an iterable value from an outer loop to an inner loop without iterating through the inner loops?

How can I move the iterable value (radio) from the outer loop to the inner one, bypassing the inner loop iteration? How can I get the value (radio) of the outer loop. I have a nested loop that generates additional …

08.07.2025
How to use Django Q objects with ~Q() inside annotate(filter=...) to exclude a value?

I'm refactoring a legacy Django Job to use annotate with filtered Count aggregations instead of querying each record individually (avoiding the N+1 problem). I want to count the number of related EventReport objects per Store, excluding those where status="C". So …

08.07.2025
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 to sign up with only the …

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

08.07.2025
Take a long time I load the Django library using PyCharm

Why does it take a long time I load the Django library using PyCharm? steps: I had created a New Project import django, but prompt error Install django Package in Interpreter it doesnt take long …

08.07.2025
How can I pass the values ​of list elements by index to the template - as the number of iterations of the loop?

How can I pass the values ​​of list elements by index to the template - as the number of iterations of the loop? I have a loop in the template and I would like to pass the number of iterations …

08.07.2025
Python manage.py migrate failed

Created a database in aws.amazon.com, edited the setting.py file in my django project, tried to migrate in the virtual environment and got error message which include as stated below: port 5432 failed: Connection timed out (0x0000274C/10060) Is the server running …

07.07.2025
The drop-down list when hovering over the element field when the contents of the line is long? (Django-Select2)

Good day! I have data to display in a row. I use such an element as a choice in a drop-down list. I have a very large long line of about 100 characters and I would like to have line …

07.07.2025
Django deploy on pythonanywhere, unhandled-exception error

I'm looking for help since I'm stuck with the deploy (for testing) of my django website. First deploy ever, so expect inaccuracies. I cannot view my site: when I click on the link I get a 'Something went wrong. There …

06.07.2025
Using Openlayers GeoTIFF sources in a django app

I have a django app with a page that displays OSM through Openlayers, I dynamically add some markers to it and now I also want to display raster overlays from .tif files. I am struggeling to implement Openlayers GeoTIFF. This …

06.07.2025
Celery Pytest integration test not working properly with django emails

I made a task for celery and tested it with as a unit with this test: @pytest.mark.django_db def test_document_expiry_alert_unit(settings): settings.CELERY_TASK_ALWAYS_EAGER = True manager = UserFactory( email="manager@mail.com", role=Role.MANAGER, organization__check_docs=True ) doc = EmployeeDocumentFactory(user__organization=manager.organization) mail.outbox = [] document_expiry_alert.delay() assert len(mail.outbox) …

06.07.2025
How to get count and show in template - Django

I was able to get the mutual friends from each users and display each mutual friends image on my template as seen in the attached image to this question. The problem now is that I was not able to get …

06.07.2025
ECS Fargate Service task running but Target Group shows unhealthy and curl to localhost:8000/health fails

Problem Summary: I’ve deployed a Django backend in ECS using EC2 launch type (not Fargate), behind an Application Load Balancer (ALB). The service runs a containerized Gunicorn server on port 8000, and the health check endpoint is /health/. While ECS …

06.07.2025
/accounts/login is not mapped when only root paths to its hosted app is not specified

I am using Django 5.2.3 and I am trying to use the built-in login system, for that I have defined the path inside my app users/urls.py: from django.urls import path, include from . import views urlpatterns = [ path("accounts/", include("django.contrib.auth.urls")), …

06.07.2025
On submitting the code, the submission is on pending [closed]

Here is my github - https://github.com/HemantRaj-2005/online-judge I am making backend in django and frontend in vite react with typescript It is a online judge, but on submitting code, it only shows pending.., getting nothing neither on console …

05.07.2025
I want to implement a reports and analytics code in django

This is the reports app for a business management website. One of its features is to identify the top selling product on the platform.Another is that it process low stock alerts,identify stock which has no sales. Also, it should display …

05.07.2025
Could not connect to Saleor during installation. Saleor URL that App tried to connect: http://localhost:8000/graphql/

I'm using self hosted Saleor and trying to integrate self hosted stripe app, however I'm getting "Couldn’t Install Stripe The auth data given during registration request could not be used to fetch app ID. This usually means that App could …

04.07.2025
How to get friends of friends (mutual friends) - Django

I have been able to get the list of all users and also implement sent friend request (following/follower). Now, how do I get mutual friends(following/followers)? For example; if both user have an existing friend in common. Below code is what …

04.07.2025
После попытки контеризировать приложения события Celery перестали обрабатываться

Я написал простой сайт на Django по покупке билетов, Celery когда пользователь начинает процесс оплаты места, оно бронируется. если через n секунд он все еще не оплатил - то оно освобождается с помощью Celery. когда я запускал сайт локально (поднимая …

04.07.2025
I am building a system mixed of tiktok and amazon store where we can post the video as well and buy products [closed]

Suggest me the technologies and the architecture that I can follow for 1 millions users

03.07.2025
После попытки контеризировать приложения события Celery перестали обрабатываться [closed]

Я написал простой сайт на Django по покупке билетов, Celery когда пользователь начинает процесс оплаты места, оно бронируется. если через n секунд он все еще не оплатил - то оно освобождается с помощью Celery. когда я запускал сайт локально (поднимая …

03.07.2025
Unable to run tests django. django.db.utils.ProgrammingError: relation "auth_user" does not exist

I'm writing tests. When trying to run it, it returns the error "django.db.utils.ProgrammingError: relation "auth_user" does not exist". I'm running the project locally using a virtual environment. There is a similar error in the logs in pgadmin. This error also …

03.07.2025
Gunicorn gevent CERTIFICATE_VERIFY_FAILED error

I have a Django website running in a Docker container (Debian), which I deploy with the following command: gunicorn core.wsgi:application --bind 0.0.0.0:8000 --workers 33 --worker-class gevent --timeout 1200 I created a simple view with an outgoing …

03.07.2025
Wagtail login downgrades to http, gives error

I am setting up a new, local version of a Django Wagtail project (which I have had running locally before). I am able to see Pages in my browser, but when I try to login (on FF, Chrome, Safari-with-no-plugins) at …

03.07.2025
Django media images not loading in production using Nginx , with Debug=False

I'm deploying my Django project with DEBUG=False, and media files like images are not loading. Nginx Configuration server { listen 80; listen [::]:80; server_name <my_server_ip>; location /media/ { alias /home/ubuntu_server02/cdo_portal/media/; autoindex on; } location / { proxy_pass http://127.0.0.1:8000; …

03.07.2025
Django-mptt using get_root() on TreeQuerySet element inside for loop and output stored in list does not persist outside of for loop

I am trying to use get_root() on individual TreeQuerySet elements in a for loop. This seems to work in the Django Python shell as shown below. Upon pressing [Enter] twice to indicate the end of the for loop, the result …

03.07.2025
Why aren't my Django Postgres `ArrayAgg` members sorting?

I'm exploring the use of ArrayAgg and I don't understand why 'histidine-[13C6,15N3]' doesn't occur before 'isoleucine-[13C6,15N1]' in this example: In [25]: for i in Infusate.objects.annotate(tns=ArrayAgg("tracer_links__tracer__name", order_by="tracer_links__tracer__name")).order_by("tns").distinct(): ...: print(i.tns) ...: ['inosine-[15N4]'] ['isoleucine-[13C6,15N1]', 'leucine-[13C6,15N1]', 'valine-[13C5,15N1]'] ['isoleucine-[13C6,15N1]', 'lysine-[13C6,15N2]', 'phenylalanine-[13C9,15N1]', 'threonine-[13C4,15N1]', 'tryptophan-[13C11]', 'histidine-[13C6,15N3]'] …

02.07.2025
Django, docker compose, whitenoise and railways: new js files not found in production (it works in local)

I am working in a django project where I have installed and configured whitenoise to serve static files in railways. But railways is not serving or collecting my new js files. In my browser I get a 404 in settings …