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

06.01.2026
Should I use Django Admin in production for a pharmacy website?

I am building my first production-ready pharmacy website using Django. The backend will be used to manage products, inventory, orders, and users. I am considering using Django’s built-in Admin interface for internal management instead of building a custom dashboard from …

06.01.2026
Navbar opacity drops and disappears when clicking links rapidly using HTMX in Django

I am building a Django website where I use HTMX to load partial HTML content when clicking navbar links (instead of full page reloads). The navbar itself is not supposed to change, only the main content area is swapped using …

06.01.2026
Click event works only for first element in loop in a Django template

I am looping around a cart dictionary that is in the session and I have defined a product for all the items. When each cart item button is clicked, they are sent via ajax, but only the first item is …

05.01.2026
Best practice for streaming large MP4 videos in browser:Django backend vs NGINX (moov atom, ranges) [closed]

I’m working on a web dashboard where users need to play large MP4 videos (around 300–400 MB) directly in the browser and switch between videos quickly (different users/patients). I noticed that if an MP4 doesn’t have the moov atom at …

05.01.2026
HTML not executing code from external JavaScript file

I wrote ajax for django to add products to cart, I use internal js which runs but when I put that code in external js file it doesn't work, Although I received the ID and csrf_token. html <main …

04.01.2026
"django.db.utils.NutSupportedError: extension 'postgis' not available" error being thrown despite having postgis installed in Python virtualenv

I am attempting to migrate model changes I have made to my codebase to a PostgreSQL server (PostgreSQL 18.1 on x86_64-linux, compiled by gcc-11.4.0, 64-bit), but every time I do this error is thrown. Specifically, the migrate sequence throws the …

03.01.2026
Excel file download via HTMX request results in corrupted or blank file

I am trying to download an Excel file (.xlsx) using an HTMX request in a Django application. The request is triggered correctly, and the response is returned from the server, but the downloaded Excel file is either corrupted or opens …

03.01.2026
What is the recommended frontend approach for beginners using Django?

As a beginner in Django, I am confused about which frontend technology to use for handling dynamic behavior. Should I start with: plain JavaScript, AJAX, or a library like jQuery? Which one has a smoother …

02.01.2026
I have 3 different account types in a Django project. Should I use 1 or 3 apps?

I'm new to Django. I've been making a project with 3 types of accounts: Schools, professors and users. But I feel like some things would be too "repetitive" like some model fields and views the views. I thought that having …

02.01.2026
I cant install taiwind css in my django project [duplicate]

(venv) PS C:\poultry_link\poultrylink> npx tailwind css init npm error could not determine executable to run npm error A complete log of this run can be found in: C:\Users\naallah\AppData\Local\npm-cache\_logs\2026-01-02T11_39_06_488Z-debug-0.log

31.12.2025
Django model with foreign key onto settings.AUTH_USER_MODEL fails when app is incorporated into other app using postgres

I have a survey app that works fine as a standalone app with no complaints (using sqlite). But when I incorporate the survey app into another that is using postgres as a database, it fails to run the survey app's …

31.12.2025
Django model with foreign key onto settings.AUTH_USER_MODEL fails when app is incorporated into other app using postgres

I have a survey app that works fine as a standalone app with no complaints (using sqlite). But when I incorporate the survey app into another that is using postgres as a database, it fails to run the survey app's …

31.12.2025
Using django-storages S3 implementation for Minio with s3v4 signature

I have "successfully" set up django-storages to work with our self hosted Minio instance. This is the settings for the setup: STORAGES = { "default": { "BACKEND": "storages.backends.s3.S3Storage", "OPTIONS": { "endpoint_url": os.getenv("MINIO_ENDPOINT_URL"), "access_key": os.getenv("MINIO_ACCESS_KEY"), "secret_key": os.getenv("MINIO_SECRET_KEY"), "bucket_name": os.getenv("MINIO_BUCKET_NAME"), …

29.12.2025
Does a ModelSerializer catch "django.core.exceptions.ValidationError"s and turn them to an HTTP response with a 400 status code?

Let's say this is my model: from django.core.exceptions import ValidationError class MyModel(models.Model): value = models.CharField(max_length=255) def clean(self): if self.value == "bad": raise ValidationError("bad value") def save(self): self.full_clean() return super().save() And I have this serializer: from …

29.12.2025
Django ManyToMany table missing even though migrations are applied (Docker + Postgres)

Problem I am working on a Django project using a PostgreSQL container in Docker. I added a ManyToManyField to one of my models. I keep migrations in .gitignore because my local and production databases are different, so I only pushed …

29.12.2025
Does Django inlineformset allow for editing & submitting related model data?

I'm attempting to display a form for a tennis event (location, time/date) and each of its participants (name, status). I was recommended to use an inlineformset, which I assume would allow editing of all those fields with one submit button. …

27.12.2025
Django ManyToMany self relationship with through model — user_from and user_to reversed behavior

I added following and followers by using intermediate model, it`s ok but does not correctly specify objects in the intermediate model. I expect the user who follows must to be in the user_from field and the one who followed to …

26.12.2025
Unsupported operand type(s) for +: 'NoneType' and 'datetime.timedelta'

I'm getting the above error while executing the following method in my django rest framework project (Django==5.0.4, djangorestframework==3.16.1). def activate( self, subscription_date=None, mark_transaction_paid=True, no_multiple_subscription=False, del_multiple_subscription=False, ): if no_multiple_subscription: self.deactivate_previous_subscriptions(del_multiple_subscription=del_multiple_subscription) current_date = subscription_date or timezone.now() next_billing_date = self.plan_cost.next_billing_datetime(current_date) self.active = …

26.12.2025
LinkedIn organizationPageStatistics API returns 400 PARAM_INVALID for timeIntervals (REST.li 2.0)

I am calling the LinkedIn organizationPageStatistics endpoint using the REST.li 2.0 API, but I keep getting a 400 PARAM_INVALID error related to the timeIntervals parameter. According to the official documentation (li-lms-2025-11), timeIntervals is an object, not a list. Error response …

26.12.2025
Which one is best for 2026 Python developers , Python Data science or Python Django?

Only Experts Can Answer this question. Which one is best for 2026 Python developers , Python Data science or Python Django? From both of these which one is easy to learn and high paid?

24.12.2025
Research survey: Evaluating Code First vs Database First in different ORMs

I am conducting an academic research study focused on comparing Code First (CF) and Database First (DBF) approaches in different ORMs. The goal of this survey is to collect objective, experience-based input from developers who have worked in real-world projects. …

24.12.2025
Почему выдает ошибку в django model?

Выдает такую вот ошибку, в чем дело? RuntimeWarning: Accessing the database during app initialization is discouraged. To fix this warning, avoid executing queries in AppConfig.ready() or when your app modules are imported. warnings.warn(self.APPS_NOT_READY_WARNING_MSG, category=RuntimeWarning) вот мой код в файле models.py: …

23.12.2025
Django DRF JWT Authentication credentials were not provided on UpdateAPIView even for is_staff user

I'm implementing JWT authentication using Django REST Framework and djangorestframework-simplejwt in my project. I have an endpoint for updating a category. What I tried Verified that the JWT token is valid. Confirmed that the user is is_staff=True and …

23.12.2025
What does _db used for in a django Model Manager

While trying to create a custom QuerySet and a custom Manager for a django Model I stumbled upon the documentation sections 1 and 2 that use the manager's _db property and i would like …

23.12.2025
Gunicorn (Uvicorn Worker) continues processing requests after Heroku 30s timeout

I’m running a Django (ASGI) app on Heroku using Gunicorn with the Uvicorn worker to support WebSockets. Heroku has a hard 30-second request timeout. When a request exceeds 30 seconds, Heroku closes the connection as expected. Problem: Even after the …

21.12.2025
Correct implementation of Wright–Malécot inbreeding coefficient using shortest paths (Python/Django)

I am implementing the Wright inbreeding coefficient (F) for individuals in a pigeon pedigree (Django application, relational database). The current implementation builds the pedigree using a breadth-first search (BFS) up to a fixed number of generations and computes F using …

21.12.2025
Existing Django project on Pythonanywhere refuses to correctly use static? [closed]

I have done the guide and yet i still cannot get it to work correctly. These two screenshots are the closest i have come to success attempt1 attempt2 This is how …

21.12.2025
Does using Django model choices for search filters add server load on every page request?

I’m building a Django-based classifieds website. Previously, my search form populated districts and categories using database queries like: districts = ( AdPost.objects .filter(admin_verified=True) .values_list("district", flat=True) .distinct() ) To improve consistency and performance, I’ve now moved both district and category to …

20.12.2025
Change color for StackedInline?

I'd like to change background color for these headers for different color (not white): Like this: My models: from django.core.validators import MinValueValidator, MaxValueValidator from django.db import …

19.12.2025
How to do nested inlines in Django?

I have models: from django.db import models class Request(models.Model): class Method(models.TextChoices): POST = "POST", "POST" GET = "GET", "GET" PUT = "PUT", "PUT" DELETE = "DELETE", "DELETE" method = models.CharField( max_length=10, choices=Method, default=Method.GET, ) url = models.TextField() class Response(models.Model): request …

19.12.2025
How to make different url aliases work for local django development

I am using django-tenants and created various aliases that all point to localhost. If the local development server is reachable via http://localhost:8000/ and I can login to the admin as expected. If I use e.g. http://other_url.local:8000/django-admin the …

18.12.2025
Django Can't find table during insert: LINE 1: SELECT 1 AS "a" FROM "qmgr_def_rules" WHERE "qmgr_def_rules"

I'm trying to add a row to my model, but it keeps coming back with: django.db.utils.ProgrammingError: relation "qmgr_def_rules" does not exist LINE 1: SELECT 1 AS "a" FROM "qmgr_def_rules" WHERE "qmgr_def_rules"... Some context: I have 3 different applications under …

18.12.2025
Django admin update get_queryset only for "change" view

In my django project admin I have an Order model. I display a bunch of information in the change page with the help of custom inlines. As I use a lot of related models, I want to …

18.12.2025
Why does Django Http404 return a JSON payload while all other Http error responses don't?

Django's http response.py library provides an Http404 class that can be used to raise a "not found" exception which returns a 404 along with the following JSON payload: {"detail":"Not found."}. However there are no other HTTP error response classes that …

17.12.2025
Dealing with m2m changes in Django on object save

So I'm building a webhook functionality for a particular Django model, as in I trigger the webhooks for 2 events. One is for creation and one for modification, as in I wanna trigger them everytime an object of that model …

17.12.2025
How to make django textfield required

I'm somehow unable to make the field required, setting null and blank to True has no effect. # models.py from django.db import models class ExampleModel(models.Model): text_field = models.TextField() # tests.py from django.test import TestCase from .models import ExampleModel …

17.12.2025
How to insert single <li>? [closed]

I am trying to handle multi-level menu with AlpineJS. Is it posible to insert single &lt;ul&gt; (or &lt;/li&gt;) in the code below? &lt;template x-if=&quot;item.has_children&quot;&gt; &lt;!-- insert &lt;ul&gt; here--&gt; &lt;/template&gt; &lt;template x-if=&quot;! item.has_children&quot;&gt; &lt;!-- insert &lt;/li&gt; here--&gt; &lt;/template&gt;

16.12.2025
Celery crashes when PgBouncer closes idle connections (idle timeouts enabled)

I’m encountering an issue when running Celery with PgBouncer and PostgreSQL after enabling idle connection timeouts. My stack includes: Django (served via Tornado) Celery (workers + beat) PostgreSQL PgBouncer (in front of PostgreSQL) Due …

16.12.2025
Django Deployment on Render: ModuleNotFoundError for WSGI Application The Problem

Demo of the Project The Problem I am attempting to deploy a Django portfolio project to Render. While the project runs perfectly on my local machine using python manage.py runserver, the deployment fails during the build process. …

15.12.2025
My Journey as a Beginner Web Developer – Need Advice [closed]

As a beginner web developer, I started my journey with HTML, PHP, and MySQL. I built only one real project, a school management system . One day, I saw someone working with React as a front-end developer. That moment really …