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

05.08.2025
'querystring' received too many positional arguments when passed a QueryDict

I'm using Django 5.2 and I can't get my head around the following issue: In my view, I have something like this: removal_qs = request.GET.copy() # contains teams=1&teams=2 removal_qs.setlist('teams', [1]) Debugging shows: In [3]: type(removal_qs) Out[3]: django.http.request.QueryDict But …

05.08.2025
Heroku not finding my static files with Django

Hello I'm on a fullstack course with the Code Instiute and both me and technical support have been stumped on this issiue: After deploying on Heroku no css or js loads or runs. error from chrome inspect console log: turnpenny-fry-syndrome-98cd38841f84.herokuapp.com/:1 …

05.08.2025
Is using Google Cloud Tasks to invoke an internal Django endpoint effectively asynchronous (even under WSGI)?

I'm running a Django application on Google Cloud Run using the default WSGI-based setup (e.g., Gunicorn/ runserver for local dev). To avoid blocking during long-running operations like third-party API calls, I'm planning to use Google Cloud Tasks. Current design: A …

05.08.2025
Django multi-app authentication: sharing custom token validation and permissions across separate codebases

I'm building a multi-platform system where I have one central authentication service (let's call it "Auth") and multiple other Django applications (App1, App2, App3) that need to authenticate users with custom tokens and permissions. Current Setup: Auth service: Handles …

05.08.2025
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 secure approach where the access token is passed in …

05.08.2025
Weasyprint Turn Off all the Warnings

Using WeasyPrint but it is always overwhelming me with INFO, DEBUB messages. How do I turn them all off? Nothing i have tried works. (Using Django) Thanks

04.08.2025
Is there a way to reduce polling woth django dramtiq

I have a webapp using django hosted on render cloud platform which allows users to make api call to deepseek. These api calls sometimes take 5 minutes to respond, and doing so with async may cause issues if user connection …

04.08.2025
Django does not automatically create test database

I have a Django project, version - 3.2.25. The problem I'm facing is that I'm unable to create a test database, when I'm executing my tests using VScode test runner. If matters here are the pytest versions: name : …

03.08.2025
Create Action Button in Open edx Admin panel using tutor plugins

I created and enabled a tutor plugin successfully using this command cookiecutter https://github.com/overhangio/cookiecutter-tutor-plugin.git How would I use this plugin to implement Admin Action Button: I have a folder adminUser with 2 files …

02.08.2025
How to make scrollable list of buttons

Needed to make scrollable list of buttons in the left part of the screen. But the scrollbar in child div, even forced by overflow: scroll is not working. Read about removing overflow from parent objects, but without success. Left only …

02.08.2025
Search filter not working Vue.js/Django(DRF)

I'm learning DRF from video, I can't figure out how to get the query parameter from vue.js in django so that the filter works. Github of the project author: Django: https://github.com/SteinOveHelset/djackets_django Vue.js: https://github.com/SteinOveHelset/djackets_vue …

01.08.2025
Using a model property (list of dictionaries) as an input to django's format_html_join() yields KeyError

I am attempting to use Django's format_html_join() util to return an html formatted version history for one of my models. But I cannot get format_html_join() to accept my list of dictionaries. Here is what the documentation suggests: format_html_join( "\n", '<li …

01.08.2025
Plotly chart not working correcly with HTMX call

I've added HTMX to my Django project, and after that my plotly chart started glitching. I generate HTML for the chart with: def get_chart(f, power, resolution): import pandas as pd yaxis_title = "Power, %" try: df = pd.read_csv( …

01.08.2025
How to add a relationship to a GeneratedField in Django

Context I have a model: class Article(models.Model): id = models.UUIDField(default=uuid4, editable=False, unique=True, primary_key=True) paper_id: UUID | None paper = models.ForeignKey["Paper"]( "Paper", on_delete=models.CASCADE, related_name="articles", null=True, blank=True, ) website_id: UUID | None website = models.ForeignKey["Website"]( "Website", on_delete=models.CASCADE, related_name="articles", null=True, blank=True, …

01.08.2025
502 Bad Gateway Nginx | Django | Gunicorn on Load Balancer

I have an AWS Elastic Load Balancer (ELB) and listeners which redirect to port 80 internally (certificates and SSL termination at the ELB). I'm running nginx on the EC2 instances, along with php, gunicorn and django/python. The cluster is being …

01.08.2025
Starting django with python manage.py runserver and getting ModuleNotFoundError: No module named '_msi'

Django was working fine my venv got corrupted and I rebuilt it from requirements.txt now getting File "C:\Users\PC\OneDrive\Documents\GitHub\DoseV3Master\venv\Lib\site-packages\msilib_init_.py", line 3, in from _msi import * ModuleNotFoundError: No module named '_msi' went to pypi and got the installer pip install python-msi …

31.07.2025
I can't Go To Definition for pytest fixtures in Cursor (VS Code)

I am using Cursor. I cannot command-click into fixtures injected as parameters in my pytests. Command-clicking to any other variable, function, class works fine. I am working in a Django Ninja project. @pytest.mark.django_db def test_deleting_an_already_inactive_channel_raises_error(mock_auth, client, client_headers, user, …

30.07.2025
What could cause a Django webpage rendering on main domain but not subdomain and localhost?

I’m trying to solve an issue with djangoproject.com. The footer on the bottom right has a “Corporate Membership” link under “Support Us”. The “Corporate Membership” link works when the url is https://www.djangoproject.com/foundation/corporate-membership/%E2%80%9D but not in case of https://docs.djangoproject.com/foundation/corporate-membership/%E2%80%9D or https://dashboard.djangoproject.com/foundation/corporate-membership/%E2%80%9D. …

30.07.2025
How can I trigger automatic actions when a model field (e.g. date) reaches a specific time like 5 days, weekly, or yearly?

I’m working on a Django-based app where developers can connect users to their apps using an account number. Once connected, a Subscription model is created with fields like user, plan, is_active, and next_billing_date. The next_billing_date depends on the plan type …

30.07.2025
How can I secure my Dockerized Django + PostgreSQL app in production on a VPS using Nginx?

I’m using Django and PostgreSQL for my web project, which I’ve containerized using Docker. I run it on a VPS and serve it with Nginx (running outside Docker). I'm concerned about the security of my PostgreSQL database and want to …

30.07.2025
Unable to properly render ModelSelect2Multiple in modal window

I have a Book model that has a authors field which is a ManyToMany field to Author model. I'm using django-autocomplete-light package to render a select2 widget in my templates that will allow me to select more than one author …

30.07.2025
Uppy with DO Storages on Django

I can not get Uppy AWS to work. I am using DigitalOcean Storage. Here is the HTML (part is GitHub Copilot): <div id="uppy"></div> <script type="module"> import {Uppy, Dashboard, AwsS3} from "https://releases.transloadit.com/uppy/v4.13.3/uppy.min.mjs" const uppy = new Uppy() uppy.use(Dashboard, …

30.07.2025
Django Admin ask for login on every click

Working on a Django project deployed on AWS. In production, I'm facing a session-related issue: When I open the Django admin site (/admin) and log in, everything works smoothly. But if I open the user site (/) in the same …

30.07.2025
Python Wand: MagickReadImage returns false, but did not raise ImageMagick exception

I've got some long-standing code in a Django code base that reads in a PDF and uses Wand to take a screenshot of the first page of the PDF, which is then displayed on the website. We …

30.07.2025
JavaScript Django default scaling using extends index

I'm using Django's template inheritance (extends) in every page of the app. The current design looks too zoomed out, and I want to adjust the default scaling through my index.html, but it didn't work. I also tried using custom CSS, …

29.07.2025
Filter Django RangeField by comparing to a point, not to another range

The PostgreSQL specific model fields docs are very specific about how to compare one RangeField to another range. But how do you compare a range to a single point? For example, if I've got a model with …

29.07.2025
502 Bad Gateway on AWS ELB with Nginx + Django + Gunicorn

Summary of Issue: 502 Bad Gateway from ELB to Django app behind Nginx + Gunicorn on EC2 Environment: Hi, I wonder if anyone can assist. I've been banging my head against a wall for over a week now, I've tried …

28.07.2025
How to use pytest fixtures in single Django TestCase test function

Test yields TypeError: test() missing 1 required positional argument: 'fix' from django.test import TestCase import pytest @pytest.fixture def fix(): return "x" class QueryTestCase(TestCase): def test(self, fix): print(fix) An almost similar case exists but I want the …

28.07.2025
Importing files twice from multiple files

Imagine i have a "first.py" file with some code in it , and then i import it in another python file called "secend.py" then i import the "secend.py" file & "first.py" into "third.py" file ,, Will this cause any …

27.07.2025
Where are these PydanticDeprecatedSince20 and RemovedInDjango60Warning warnings coming from?

I am getting the following output in my warnings summary: venv/lib/python3.11/site-packages/pydantic/_internal/_config.py:323: 15 warnings /Users/darshankalola/Desktop/roon-be/roon-doctor-service/.venv/lib/python3.11/site-packages/pydantic/_internal/_config.py:323: PydanticDeprecatedSince20: Support for class-based `config` is deprecated, use ConfigDict instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.11/migration/ …

27.07.2025
Replacement for migrate --skip-checks

I am having some issues with the latest version of Django. It seems they have removed the --skip-checks option from the manage.py migrate command. The problem I am getting is that the app (that was working on 4.2) is trying …

27.07.2025
Htmx web socket extension not rendering server messages

I'm using the below to render model initial counts on load. consumers.py: from channels.generic.websocket import WebsocketConsumer from django.template.loader import render_to_string from myapp.models import Model1, Model2, Model3, Model4 class DashboardHeaderConsumer(WebsocketConsumer): def update_dashboard_counts(self): stats = [ {'name': 'Model1', 'value': Model1.objects.count()}, {'name': 'Model2', …

27.07.2025
Django + Tailwind CSS deployment failing on Railway with Procfile parsing errors

I'm trying to deploy a Django application with compiled Tailwind CSS to Railway, but I keep getting Procfile parsing errors. The build process works fine (Tailwind compiles successfully), but the deployment fails during the Procfile parsing stage. Error Message Nixpacks …

26.07.2025
404 not found error Django URL with JavaScript fetch function

I'm building a Todo app with Django and JavaScript. I've reached the point where when I click a "trash" button, the note should be deleted, but it shows an error in the console, the reason for which is not clear …

26.07.2025
Django "makemigrations" stuck for ever

When I run python manage.py makemigrations, it just gets stuck. No matter how long I wait, it stays frozen forever—no logs, no output, nothing. I even changed my PostgreSQL database to the default SQLite database in settings.py, but it still …

26.07.2025
Django filter an m2m relation by a list of inputs (which must all match)

Let's take some Store and Book models as examples: class Book(Model): title = CharField(...) ... class Store(Model): books = ManyToManyField('Book', blank=True, related_name='stores') .... I receive a list of book titles and must return stores linked to those books. I …

25.07.2025
How I push Django database sqlite3 and media folder on github for production server

The problem occurs when I delete the db.sqlite3 and media on .gitignore file. and write add command git add -A. the error comes fatal:adding files fail PS C:\Users\user\OneDrive - Education Department, Government of Punjab\Desktop\Django demos\Blog> git add -A error: read …

25.07.2025
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 results to 65 per page. Despite setting the pagination_class …

25.07.2025
GetCSRFToken is not defined error, JavaScript

This is the part of the code in the Django + JavaScript Todo App that is responsible for deleting a note. I need a csrftoken for this, but the JS is showing me an error in the console. What did …

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