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

18.05.2024
How to upload and store multiple images in Django 4

Django 4 Need user to be able to upload either an archive of images or just a few images at a time. Then these pages are numbered according to the order in which the user has placed them and stored …

18.05.2024
Why recognize my models in an other app in django how can i call models in other app

From product.models import Product CART_SESSION_ID = 'cart' class Cart: def __init__(self, request): self.session = request.session cart = self.session.get(CART_SESSION_ID) if not cart: cart = self.session[CART_SESSION_ID] = {} self.cart = cart def __iter__(self): cart = self.cart.copy() for item in cart.values(): item['product'] = …

18.05.2024
[Nginx][Django] Cannot access the media files in production via Nginx

I am trying to access the media files using Nginx. The file exists in the directory: /usr/src/app/backend/media/profile/c4ebe33d-7da1-4a62-bb17-8da254d69b36, where the part profile/c4ebe33d-7da1-4a62-bb17-8da254d69b36 is created dynamically. The media root is: /usr/src/app/backend/media. I know the file exists cause I am able to see …

18.05.2024
When I console.log fetched data it appears as undefined but it appears when I refresh

I have this function in react to fetch the data from my django API: const [filterData, setFilterData] = useState([]); const fetchFilterData = async () => { const filter_url = 'http://127.0.0.1:8000/api/filters/' try { const response = await fetch(filter_url) const result = …

18.05.2024
Django Deployment failed during build process on railway

When I deploy my Django app on rail after adding nessary variables and updated file everything done unless this failed do u know why and how to fix it Build logs on railway;here the problem how can i fix it"#8 …

18.05.2024
Nothing happens when transferring data to the database

I have a problem. I'm new to django. And so the error lies in the fact that nothing happens during the data transfer. The database is not being updated. I will be very grateful for your help! this is code: …

18.05.2024
Data Flow in Django Rest Framework?

I have recently started learning Django Rest Framework, and hit a little roadblock trying to understand the data flow in DRF. From what I understand, views take in a web request and return a web response, so they are the …

18.05.2024
Django Model Form, seems like there is an anomaly where my user creation form's clean_username method is not throwing a ValidationError when it should

Background I have a custom User model that I have extended from BaseUserManager and AbstractBaseUser. Similarly, I have a custom sign-up form that I've extended from UserCreationForm (all these custom items are extended from django.contrib.auth). The custom UserCreationForm I've made …

18.05.2024
Cant run django-admin in windows11

I was trying to start a new project in django and ran into this error.enter image description here i already created venv and installed django with venv activated.But even after successfull installlation of django i can't run …

18.05.2024
I want to add CMS feature in my current website, which lib would you recommend? [closed]

Curretly, I want to add CMS feature in my current website, which lib would you recommend? Hi, I already using Django build a simple website, but don't have CMS feature yet. Recently, I want to add CMS feature in the …

18.05.2024
Displaying images from static folder in Django

We have a problem with displaying images on html pages. We create graph, save it and then pass it's url to html page via context, but django can't find the picture (Error 404 Not Found). There's no model to store …

18.05.2024
Mock patching an endpoint unittest that makes several requests to third party

I have a single endpoint written using django ninja. This endpoint executes a crawler that performs several requests. The sequence of requests has 3 different routines depending on whether or not the crawler already has valid login credentials in its …

18.05.2024
KeyError error at /registration/register/ 'email'

I have a problem. When clicking on the link http://127.0.0.1:8000/accounts/register / returns the KeyError error at /accounts/register/ 'email'. I program in django in pycharm. I want to point out that there is a specific 'email' error here! …

18.05.2024
How to reverse a URL in format namespace:view:endpoint?

I have a Django project with the following urlpattern defined on project level: urlpatterns = [ path('', include(('ws_shopify.urls', 'ws_shopify'), namespace='shopify')), ] The file ws_shopify.urls defines the following urlpatterns: urlpatterns = [ path('api/shopify/', ShopifyWebhookAPIView.as_view(), name='webhook'), ] The class ShopifyWebhookAPIView …

18.05.2024
Django admin causing latency to load instances , the models have a related hierarcy [closed]

Case: I have relationships: 1 Distributor:M resellers, 1 reseller: M customers, 1customer: M domains, 1 Domain: M mailboxes. The model admin panel is taking a long time to load the objects for all the model admin. Does the default django …

18.05.2024
Django: How to use CURSOR .. WITH HOLD in Django ORM

In Django orm we have queryset.iterator https://docs.djangoproject.com/en/5.0/ref/models/querysets/#iterator that uses under the hood Postgres cursor www.postgresql.org/docs/current/sql-declare.html in case we using Postgres as a database of course. By default Django uses it with WITHOUT HOLD setting, …

18.05.2024
Can we use post_save signals in apps.py?

There. I'm using django python. I've custom user model. I've created a separate django signals file. there is my method. I'm importing them in my apps.py and wanting to use there. cause, post_migrate signals are working that way. but post_save …

18.05.2024
How to show request body using django rest framework and drf_spectacular in function based views

I have the following problem, which has been difficult for me to find documentation on function-based views to document them with drf_spectacular since all this is found for class-based views I have tried different ways to document the requestBody in …

18.05.2024
Generate SQL joins from list of Django models

Given a list of arbitrary Django models, how can you use the Django ORM to generate the JOIN statements for an SQL query? This of course will only work if the relationships are defined in the model and there is …

18.05.2024
Use ajax with django

I already created an animation in dom for the login and registration but the only thing I need is to validate the registration and I already have the registration with django but I need it to show me the error …

18.05.2024
Django local server doesn't update web site with the new data from the database

CRUD operations are working just fine when I check the admins site. All of the new created items, updated or deleted are shown in the admins site, but in order to make the data appear in the website I have …

18.05.2024
Sending email Django with mailtrap

Hi I finished making my contact form but it doesn't let me send email, I'm using mailtrap as a test server but I get an error. I'm using Django 5.0 and Python 3.10 Settings.py # Email config EMAIL_HOST = 'sandbox.smtp.mailtrap.io' …

18.05.2024
Is there a way to insert a default field to each user's 'wincon' model or lock the form field to a value based on another form field?

I am building a game tracker. I would like to have it where if the user selects anything other than 'Win' then the wincon field of the form is unchangeable or set to a default field. This is to make …

17.05.2024
Django and IIS (wfastcgi.py, httpPlatform or ...)

I need to run next some years Django on IIS (don't ask why :-). I found two ways https://learn.microsoft.com/en-us/visualstudio/python/configure-web-apps-for-iis-windows?view=vs-2022 1. httpPlatform + runserver wsgi.multithread:True wsgi.multiprocess:False The solution is multithreaded, working almost well, low resources, good performance. 2*5 …

17.05.2024
Is it possible customize drf api root and grappeli in a Django Project?

I am using Django Rest Framework and Grappelli in my Django project. I need to add a cookie consent notice. Is it possible to customize both to show the notice? Do I need to create a new template?

17.05.2024
Django form submission not redirecting to success page and the post request is not being done

I'm encountering an issue with Django where form submission is not redirecting to the success page as expected and the data input its not happening . Here's a breakdown of the problem: I have a Django application where users can …

17.05.2024
Docker compose enter debug mode upon breakpoint while dropping stdout from web server

Have a question on using docker-compose when entering into debug mode by manually setting breakpoint(). This is my service and it has a /health which calls almost every 5s, and it prints out 200 status code to stdout. However, when …

17.05.2024
Displaying an image doesn't work Django python

So this is my views.py when I use atrakcjatest my images work, but when I try to use the filtered atrakcja(atrakcje_list) it doesnt work and only images dont work, the rest of variables are ok def map_view(request, trasa_id): trasa = …

17.05.2024
I want to deploy my django project on render but it show not build wheels for dlib

I want to deploy my django project which is face recognition for online transaction on render but it show ERROR: Could not build wheels for dlib, which is required to install pyproject.toml-based projects how could i resolve this ? i …

17.05.2024
Django Graphene GraphQL customize Error messages

In my Django app with Graphene for GraphQL, how do I intercept the Graphene GraphQL messages so I can sanitize the content? I tried creating a custom graphql view and a custom_execute function and using that in the urlpatterns endpoint …

17.05.2024
Django View Not Returning 404 as Expected When Form is Submitted

I'm facing a strange issue with Django. I have set up a simple form in a template that submits to a view, but I'm not getting the expected 404 response. Instead, I'm being redirected to the URL http://localhost:8000/clear/ without seeing …

17.05.2024
Deploying Django AI on Heroku

I'm having trouble uploading my Django web app to Heroku due to the Slug Size limit. My web app includes an AI API that requires a torch dependency. This is the error: Compressing... remote: ! Compiled slug size: 700M …

17.05.2024
Django bulk update with batch in multiple transactions

I've a certain code that updates bulk rows: from simple_history.utils import bulk_update_with_history from django.utils.timezone import now bulk_update_list = [] for chart in updated_chart_records: chart.coder_assignment_sequence = count chart.queue_id = work_queue_pk chart.level_id = role_id updated_num = bulk_update_with_history(bulk_update_list, Chart, ["coder_assignment_sequence", "l1_auditor_assignment_sequence", "l2_auditor_assignment_sequence", "l3_auditor_assignment_sequence","queue_id", …

17.05.2024
How to pass on the chopped details from URL in Django?

I have a project with the following urls.py. urlpatterns = [ path('category*/', include('student.urls')) // * could be replaced by a number ] In that project I then have an application student whose urls.py looks like this: <pre …

17.05.2024
How to take data from HTML Inputs and use them in a form?

I am trying to get the user's login and password from the HTML template (from ) and use these inputs for processing. I want to use the inputs from the HTML template and not the usual Django forms, like: &lt;label …

17.05.2024
Deleting resource of a django model with foreign key

I have following django models : class ModelA(models.Model) : # fld1, fld2 class ModelB(models.Model) : fld_a1 = models.ForeignKey(ModelA, related_name='modela_1') fld_a2 = models.ForeignKey(ModelA, related_name='modela_2') # other fields Now when I delete resource from ModelB, how to make sure that the …

17.05.2024
Celery executes tasks sequentially, one after another

I have a Django application that has large I/O-bound tasks. I use Celery to run these tasks in threads and manage the progress in the UI with a progress bar. Here's my configuration : Django version : 5.0.2 Celery version …

17.05.2024
How to fix CSRF TOKEN being overwritten with form data after submission failed in django?

I building a multitenants project using django-tenant and django-tenant-user but I am facing a weird issue where the CSRF TOKEN and email fields of my login form are being overwritten with the password data after a failed login attempt. Please …

17.05.2024
Get User Information in Django

I have made a REST API using Django, and I have issues with retrieving a user's information by inserting a token. I am using the User model. So here is the view: class getUserInfoView(APIView): #generics.RetrieveAPIView #authentication_classes = [authentication.TokenAuthentication] …

17.05.2024
Custom view on admin main page

I want to show some information on the admin index.html, but I do not want to use context processors for this, but have my own view. So I tried like described in the docs and discussed <a …