"Вопросы и ответы" Django и Python, страница 3

15.06.2025
How to access a Django site from another device on a local network

I'm running a Django site on my computer and I want to access it from another device on the same Wi-Fi network (for example, from a phone or another laptop). I tried running python manage.py runserver, but I can only …

14.06.2025
Unable to find GDAL library in conda env

I have a Django project configured with PyCharm. I am using a conda env for packages installations. I have installed gdal. But when I run server, I see: django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal310", "gdal309", "gdal308", "gdal307", …

14.06.2025
Не работает команда collectstatic в проекте Django

При вводе команды 'python manage.py collectstatic' в командную строку в Visual Studio 2022 выводится ошибка: 'You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path.' Вроде как путь указан криво. А он указан вроде нормально, …

13.06.2025
Why is my selenium script blocked in production in headless mode, while it works completely fine in local enviroment? i use python

I have a selenium web scrapper, that runs well in my local development environment even in headless mode. However when i deploy it in production in a Linode Ubuntu VPS, somehow it fails with a Timeout exceeded message.Any help would …

13.06.2025
Shouldn't the call to django_stubs_ext.monkeypatch should be inside a TYPE_CHECKING check?

Simple question here about django_stubs_ext. Shouldn't the monkey patching occur only during TYPE_CHECKING ? Something like this: # settings.py if TYPE_CHECKING: import django_stubs_ext django_stubs_ext.monkeypatch()

13.06.2025
Pythonanywhere getting an error when deploying [closed]

Something went wrong :-( Something went wrong while trying to load this site; please try again later. Debugging tips If this is your site, and you just reloaded it, then the problem might simply be that it hasn't loaded up …

13.06.2025
How do I structure a Django REST Framework API backend when the frontend is already built?

I'm building a Visitor Management System (VMS), and I've been given a complete frontend to work with. My task is to build the API-based backend using Django and Django REST Framework, which I'm familiar with from smaller projects. However, I'm …

13.06.2025
Django-minify-html breaks Google Analytics injection

I'm running into an issue and would appreciate some pointers. I have a production Django app where I included Google Analytics using a context processor and conditionally render it in my base.html template like this: <!-- Google Analytics --> …

13.06.2025
Webapp deployment issue in shared hosting

Can anyone tell me how I can deploy my Django React-based webapp in my shared hosting

12.06.2025
FileNotFoundError: Could not find module 'gdal.dll' when running Django with GeoDjango on Windows (Conda environment)

I'm working on a Django project using GeoDjango for spatial models. I'm on Windows 10, using a Conda environment (moodspend). When I try to run the server with: python manage.py runserver I get this error: (moodspend) PS C:\Users\ngari\Desktop\Ngari's Projects\moodspend\backend> …

12.06.2025
Возможно ли сделать групповую обработку в админке Django?

Доброго времени суток! Я в Джанго новичок. Возможно ли такое организовать? Необходимо вывести три поля на форму, сделать по ним отбор, затем выбрать какое-то значение и записать его в тот набор, который получился в результате отбора? По одному полю нужно …

12.06.2025
How can I send a column from one field of the queryset model to the form?

Good day! I have a model table. And a form. I filter the query from the queryset model by certain criteria and send it to the code in views. From the filtered queryset I would like to take only one …

11.06.2025
How do I write a Django ORM query that returns a match based on an intersection of lists?

If I have, for example: from django.contrib.postgres.fields import JSONField class MyModel(models.Model): data = JSONField() GIVEN a model instance obj1, where data == ['apple', 'banana', 'orange'] GIVEN a model instance obj2, where data == ['banana', 'orange'] GIVEN a model instance …

11.06.2025
Should I really use React/Vue with Django instead of Alpine.js? [closed]

I have a page where user creates an instance. An instance has a bunch of characteristics and foreign key to product (which has category and name itself) and all the fields are static - just stylized selects and inputs, but …

11.06.2025
How can I convert the last / any row of a model / queryset into one dictionary? [closed]

Good day! I have a table model. I plan to take one row from it - one set of elements. To place it in an object - a dictionary. How can I place the last or first or a specific …

11.06.2025
React + React Native + Django AllAuth

I'm running a Django server which has API's I consume through a React Native and React applications. I want it to work for Google, Facebook, Instagram and Twitter. For this question I want to focus on the React Application and …

11.06.2025
Django Sitemap issue: GSC fail to fetch sitemap with error "Sitemap could not be read"

I created sitemap using django default sitemap from django.contrib.sitemaps.views import sitemap Here is the complete process #urls.py sitemaps = { 'static': StaticViewSitemap, 'blogpost_detail': BlogSitemap, 'portfolio-details': PortfolioSitemap, # Add others like 'posts': PostSitemap if needed } path( "sitemap.xml", sitemap, …

11.06.2025
Django admin site is looking for a template: <project_name>.html ...I want to use the default template

My project's admin site was working earlier with everything kept at default. But I'm building the site and after lots of coding I get an error where it is asking for a template that has the name of the project. …

11.06.2025
How Does Connection Pooling Work In Django?

If I'm not wrong, currently there are two ways to have connection pooling in Django: Native Connection Pooling (Django 5.x) Using PGBouncer I want to know that how connection pooling works behind the scene in Django. In FastAPI, …

10.06.2025
How can I fill in related models separately through forms (OneToOneField)?

I have two table models. I write data to one of them using a form. I also want to write data to the other model table using a form. But I'm trying to link these tables. Use the first one …

10.06.2025
Gunicorn + Gevent + Opentelemetry

Anyone using Django + Gunicorn + Gevent + Opentelemetry in production? Would love to know how you got it to work. Seems like I can't seem to use BatchSpanProcessor or BatchLogRecordProcessor. I'm getting errors which seem to have many open …

09.06.2025
Role and Permission in Django DRF

I am implementing permission-roles in Django using DRF but not sure where i got stuck here Here are models: class User(): class Staff() user = models.ForeignKey( User, on_delete=models.CASCADE, related_name=&quot;staffs&quot;) business = models.ForeignKey( &quot;Business&quot;, on_delete=models.CASCADE, related_name=&quot;staffs&quot; ) role = models.PositiveSmallIntegerField (superadmin, …

09.06.2025
Is there a way to test blog post permissions in PyTest?

I've been trying to make the final test pass. I seem to be getting a 403 error, nothing that I'm not authorized to make a post. Even though I gave the test user authorization to post tests. I don't understand …

09.06.2025
How do I prevent a user from creating multiple objects within 24 hours in Django

I'm trying to prevent users from creating more than one Mining object within a 24-hour period in my Django project. I chose to use Django signals, specifically the pre_save signal, to enforce this rule globally—regardless of whether the object is …

09.06.2025
Trying to send basic string to Django Backend via POST request using axios but no data is sent

I've been trying a basic string to Django backend from frontend using axios.post call. Connection is ensured and backend side detects the request but the data is empty. Frontend side: const axios = Axios.create({ baseURL: API_URL, headers: { 'Content-Type': 'application/json', …

09.06.2025
How to get Custom Adapter to respect the 'next' URL query parameter

I am using allauth in my Django project and I have set up a custom account adapter which I have specified in settings.py - ACCOUNT_ADAPTER. My issue is once the user logs in in at a URL like /accounts/login/?next=/checkout/, my …

08.06.2025
Не работают ссылки на сайте в Django

Не работают ссылки, хотя вроде всё прописано верно. В файле urls.py: from django.urls import path from . import views urlpatterns = [ path ('', views.reg, name = 'Reg_page'), path ('about/', views.about, name = 'About') ] В файле views.py: def …

08.06.2025
Django Field errors not displaying

Here is my forms.py code: from .models import User class userRegistrationForm(forms.ModelForm): password = forms.CharField(widget = forms.PasswordInput()) confirm_password = forms.CharField(widget = forms.PasswordInput()) class Meta: model = User fields = ['first_name', 'last_name', 'username', 'email','password'] ``` Here is my views.py code: …

08.06.2025
Фоновые задания в Джанго

Никак не могу понять - с какой стороны подойти к такой задаче: В базу надо записывать данные с определенной периодичностью. Как в Джанго реализованы фоновые задачи, выполняемые по расписанию? В идеале было бы хорошо создать внутри скрипт и заполнять данными …

08.06.2025
Django - Testing async management command not working as expected

To give some context, i made a async function which works fine when testing manually but when I use Django's testcases, the query is not returning anything back inside the async block, if I try the same query outside, it …

07.06.2025
Add functionality to model creation in django admin site

I creating a website using django. I want to add extra functionality to model creation and changing pages in standard admin site, that is input text field and button. Idea is to paste a link to post on another website …

07.06.2025
How to efficiently combine Redis-based recommendation scoring with Django QuerySet for paginated feeds?

I'm building a marketplace app (think classified ads with negotiations) and trying to implement a personalized recommendation feed. I have a hybrid architecture question about the best way to handle this: Current Setup: Django backend with PostgreSQL for product …

07.06.2025
'User' object has no attribute 'profile' django profile update problem

I am new to django and currently learning and i have encountered a problem that i just cant seem to solve. from django.shortcuts import render, redirect from django.contrib import messages from .forms import UserRegisterForm, UserUpdateForm, ProfileUpdateForm from django.contrib.auth.decorators import login_required …

07.06.2025
How to integrate a PyTorch YOLO ensemble model (.pt file) into a Django web app for real-time image predictions?

I'm building a Django web app where users can upload images to detect objects using a YOLO ensemble model saved as a .pt file. This model includes keys like 'model', 'names', 'stride', and 'ensemble_info'. So far, I can load the …

07.06.2025
How to make a one-off charge (no UI) reusing the saved customer after initial Checkout?

I’m implementing payments with Stripe and I’ve run into a flow I don’t know how to solve. I’d like to know the right or recommended way. Scenario First payment with UI: The user goes to my frontend, I use …

06.06.2025
Wagtail - How can I use a custom StructBlock with programmatically assignable default values?

I have created a StreamField for some of the site's settings. This StreamField contains a collection of a custom StructBlock, named FacetBlock. FacetBlock contains a BooleanBlock, a CharBlock, an IntegerBlock and a ChoiceBlock. Now I need to make the CharBlock …

06.06.2025
Performance issues when using Django's Min('id') in big table

I have a model Table which gets a new entry every few seconds, so it's a quite big table. class Table(models.Model): id: int pk: int timestamp = models.PositiveBigIntegerField(db_index=True) Now what i am trying to do is get …

06.06.2025
CS50W Project network, can't figure how to implement the Paginator

I've been trying to implement the paginator function for about two months now. I've tried many different approaches, but they always lead to new bugs. In views.py, I load the posts and send them to JavaScript. In loadPosts and loadProfile, …

05.06.2025
Django Celery: 6-second delay to register task from UI in Kubernetes environment – resource allocation?

We are seeing a ~6-second delay when a Celery task is triggered via the Django UI (e.g., my_task.delay()). Our stack runs on Kubernetes, and I'm wondering if this lag is due to resource constraints or something else. Key Services and …

04.06.2025
Getting "MySQL server has gone away" error on cPanel-hosted Django site

I'm hosting a Django project on a shared server using cPanel, and I’ve been running into a frustrating issue lately. On several pages across the site, I get a 500 Internal Server Error. After checking Sentry, I consistently see this …