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

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 …

17.05.2024
Why doesn't the django program keep an up-to-date log, but uwsgi does

I used uwsgi to start my project, and then I logged it in my uwsgi configuration, and then I logged it in my django project setup file, but I found out today that my django log only logged this morning …

17.05.2024
Saving instance of model prior to sending out response in Django

Is there a way to add a record to me DB BEFORE sending off a response? I just learned about Django Signals so I assume that might be a candidate. The reason why I'm asking this is because of an …

17.05.2024
Advice on using patch file in django for installed library

I am using rest_framework_simple_api_key in my production application on python version 3.9 . On running command python generate_fernet_keymanage.py as given in doc(djangorestframework-simple-apikey) i am getting File &quot;C:\Users\DELL\anaconda3\lib\site-packages\rest_framework_simple_api_key\models.py&quot;, line 15, in &lt;module&gt; class AbstractAPIKeyManager(models.Manager): File &quot;C:\Users\DELL\anaconda3\lib\site-packages\rest_framework_simple_api_key\models.py&quot;, line 16, …

17.05.2024
TypeError: 'class Meta' got invalid attribute(s): manager_inheritance_from_future in Django4.2

I got above error while running the makemiragtions command. So I delete/renamed the existing migration folder and rerun the makemirations command it's is migrated but when I run the migrate I got same error i.e., TypeError: 'class Meta' got invalid …

17.05.2024
Where to add css files within django project

I'm building a To Do list in Django by following a tutorial, I'm trying to make seperate CSS file instead of directly writing it within HTML file, However i'm recieving 404 error. Below is directory structure ├─ base/ │ …

17.05.2024
Django: how to create a unique instance of one model as a field in another model

I am trying to store an instance of an Item model as a field in my users model using ForeignKey like so: class UserProfile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) username = models.CharField(max_length=255) items = models.ForeignKey('Item', on_delete=models.CASCADE) def __str__(self): return …

17.05.2024
Why will my Django middleware redirect googlebot instead of directly allowing it?

Class BlockDirectAPIAccessMiddleware: def __init__(self, get_response): self.get_response = get_response def __call__(self, request): protected_paths = ['/api/socialinfo', '/api/crypto-data'] if any(request.path.startswith(path) for path in protected_paths): googlebot_user_agents = [ &quot;Googlebot&quot;, &quot;Googlebot-Image&quot;, &quot;Googlebot-News&quot;, &quot;Googlebot-Video&quot;, &quot;Storebot-Google&quot;, &quot;Google-InspectionTool&quot;, &quot;GoogleOther&quot;, &quot;Google-Extended&quot; ] # Check for Googlebot (allow access) user_agent …

17.05.2024
Issue connecting MySQL to Django [duplicate]

My Django project will not migrate the changes I have made to the settings.py I get this error (1045, &quot;Access denied for user 'root'@'localhost' (using password: NO)&quot;) I installed and setup a MySQL created a database connected all the information …

16.05.2024
Image gallery using magnific-popup always popup first one, not the one selected when clicked

I'm using JQUERY and Magnific Popup in a django project. When I clicked on any image in the gallery, it always popup the first image instead of the one selected. This is my current code: Here is the django template …

16.05.2024
Django (DRF) Channels getting SynchronousOnlyOperation on deleting User instance

I'm using DjangoRestChannels (based on Django Channels). I made a simple comments page. When new Comment added by any User instance consumer sends in to JS and renders on HTML. Everything works exceps when User instance gets deleted I'm getting …

16.05.2024
Error in vercel while uploading a django app

While trying to upload my Django application I got these errors requirements.txt error: subprocess-exited-with-error × Getting requirements to build wheel did not run successfully Error: Command failed: pip3.12 install --disable-pip-version-check --target . --upgrade -r /vercel/path0/requirements.txt error: subprocess-exited-with-error how do …

16.05.2024
How to efficiently convert denormalized data to JSON?

I am learning django and couldn't find an answer on this. I am receiving data a query in denormalized form. Here is how it looks like. Store_id Shelf_id Product_id Qty store1 …

16.05.2024
Upgrading postgres version in django error

I'm trying to get postgres 14 (upgrading from 11) to work locally. Initially the docker file looked like: db: image: postgres-14.11 environment: volumes: healthcheck: test: timeout: 20s retries: …

16.05.2024
Error in django KeyError at /accounts/register/

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 this is code: registration/urls.py: from django.contrib.auth import views as auth_views from django.urls import …

16.05.2024
Bad Request (400): Django / Nginx / Gunicorn / Kubernetes

I have a Django project running on Kubernetes with Redis, Postgres, Celery, Flower, and Nginx. I deploy it using Minikube and Kubectl on my localhost. Everything looks fine; the pod logs appear good, but when I'm trying to tunnel the …

16.05.2024
Django 5 use of static files with images

I´m trying to a picture to website with help of Django 5 and static files, the website its self is working with no error is diplayed in Django 5 but image is not displayed Has tried to read the documentation …

16.05.2024
How to deal with Django and TimescaleDB hypertables?

Firstly hypertable needs all PK contains partition column, in this case time, and in the other hand Django does not allow create multi column PK so you can't create a PK that could contains the time column. Second: if I …