Django.fun

Questions & Answers about Django, page 3

Pylance, functions not defined

I have a simple code with 3 functions. the first one get some values from the 2 others to check some conditions, but I get an error from Pylance saying the functions sub1 and sub2 are not defined. any clues? …

Template variables doesn't updates after redirect in Django?

I am building simple django app where I want to do some parsing when user click button on the frontend. I have template variable {{ parsing }} which I am using inside index.html to disable button for parsing when user …

Python NameError: name '_mysql' is not defined

I am trying to have a working ubuntu server with Python, Django and MySQL. But when I switch from SQLite to MySQL and trying to reach my server I get the following error "NameError: name '_mysql' is not defined". It …

How to get the Current User IP in Python / Django

I am trying to capture the IP Address and the System Name of the current Login user during the login Process. I Use following code for the same: import socket system = socket.gethostname() IPAddr = socket.gethostbyname(system) It works fine …

Django: Can't login with Allauth

I tried all login, signup process with usign allauth in Django. But I have this problem: File "C:\Users\Mircal\Desktop\Project\core\urls.py", line 22, in <module> path('accounts/login/', name='account_login'), TypeError: _path() missing 1 required positional argument: 'view' core/urls.py from django.contrib import admin from django.urls …

How to plug a function inside ImageField

I'm trying to upload images from Django admin. the files are bigger most of them more than 5 MB, I want to rescale them so the size should be less than 1 MB before upload. I have a function that …

TemplateDoesNotExist heroku working fine on local

When Deploying to Heroku throws an error TemplateDoesNotExist but it works fine on local

Django and Celery logs

We have a Django app (with Celery) that process several tens of thousands of http requests per minute. We are getting a huge volume of logs from Django like ip... - - [date...] "POST /url... HTTP/1.0" 200 311 "-" "libcurl-agent/1.0" …

Different serializers based on user object rights

I'm looking for a way to use different serializers within a ModelViewSet depending on the request.user properties making the call. Case 1: The request.user is the owner of the profile and must use the serializer called 'UserProfileOwnerSerializer' which allows a …

Django - tensorflow: ModuleNotFoundError: No module named '_ctypes'

I'm using tensorflow in a django project, when I try to use tensorflow I'm getting this error: ModuleNotFoundError: No module named '_ctypes' I'm using ubuntu 22.04 and python 3.10 I already tried : sudo apt install libffi-devel but it doesn't …

How can I optimze Django Code to only one query request

I have a simple django project which displays previous reservations dates based on id's. However currently there are 2 requests being made. (N+1 sql requests, where N is the reservation’s count) Do you have any idea how i would be …

Add multiple values to a django model's attribute

I want to add an attribute to a django model as much as the user wants to. For example I want to add a few academic degrees class Employer(models.Model): academic_degree = models.CharField(max_length=100, null=True, blank=True) with this code We can …

Using Bootstrap tab view in Django

I am trying to implement tabs using Django and Bootstrap. The following code does not switch tabs properly and the contents of all tabs are displayed on the active tab. Also, tab switching is not working even thought URL is …

Как перебрать текст из базы данных Django

У меня есть текст в базе данных и есть несколько картинок, которые нужно вставить между строк этого текста, но я не знаю как можно перебрать текст из бд. Может существуют другие варианты решения, подскажите пожалуйста html <div> {{blogDB.blog_title}} {{blogDB.full_text|safe}} {%for …

django-python unsupported operand type(s) for -: 'float' and 'decimal.Decimal'

I don't know how to fix this, I already tried to change int to float and it didn't work, I need help :(, if anyone has any ideas I'd appreciate it '''def get_total(self): # recupera desconto e atribui 0 se …

Simplifying flags when filtering models

I have a user model that has a set of notifications: class User(AbstractUser): # Notification flags send_to_all = models.BooleanField(default=True) send_to_me = models.BooleanField(default=True) send_to_friends = models.BooleanField(default=True) # ... I am passing them from front-end to my views where I trigger …

How to upload data like images, PDFs and excel files in DevExtreme File Manager?

I have an app in which I want to show the replica of the google drive folder structure in my app. I can get data from google drive via its API. But I do struggle in uploading that data to …

How to perform sum aggregation on n number of documents after sorting records (descending) ? elastic

{so, i want latest 30 document between 20/6 to 20/4 and perform the sum aggregation on field duration_seconds of those 30 latest doc. we had tried multiple aggregation on that like top_hits, terms for sorting but then we got the …

django-tenants: Python shell with specific tenant

I want to use "./manage.py shell" to run some Python commands with a specific tenant, but the code to do so is quite cumbersome because I first have to look up the tenant and then use with tenant_context(tenant)): and then …

React i18next doesn't display translation after running npm build

React i18next fails to fetch translation from the JSON file after running the build command. Note, everything works fine without the build in react localhost:3000 I'm using React build file in Django. I checked a similar issue but the solution …

1 2 3 4 5 1807 1808

Tutorials

Современный Python: начинаем проект с pyenv и poetry

Настройка проекта Python — виртуальные среды и управление пакетами

Использование requests в Python — тайм-ауты, повторы, хуки

Понимание декораторов в Python

ProcessPoolExecutor в Python: полное руководство

map() против submit() с ProcessPoolExecutor в Python

Понимание атрибутов, словарей и слотов в Python

Полное руководство по slice в Python

Выпуск Django 4.0

Безопасное развертывание приложения Django с помощью Gunicorn, Nginx и HTTPS

Автоматический повтор невыполненных задач Celery

Django REST Framework и Elasticsearch

Докеризация Django с помощью Postgres, Gunicorn и Nginx

Асинхронные задачи с Django и Celery

Релизы безопасности Django: 3.2.4, 3.1.12 и 2.2.24

Выпуски исправлений ошибок Django: 3.2.3, 3.1.11 и 2.2.23

Эффективное использование сериализаторов Django REST Framework

Выпуски безопасности Django: 3.2.2, 3.1.10 и 2.2.22

Выпущенные релизы безопасности Django: 3.2.1, 3.1.9 и 2.2.21

Обработка периодических задач в Django с помощью Celery и Docker

View all tutorials →