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

08.05.2024
Trouble in installation of django

I have been facing many issue regarding installation django on windows using pip. i have used "pip install django". But I am unable run the command "django-admin startproject myproject" it is showing following error: 'django-admin' is not recognized as an …

08.05.2024
How to test django channels between two physical devices over a wifi network

Can someone help me configure my django channel app in order for me to be able to test the chatting feature between two users. They must use two different devices and chat over a wifi network Looking through the net …

08.05.2024
Communication between the server and the user

Front end (React) and Back end (Django) are working on the local server and are sending information to the user, but the Front end code has been updated and the local server is working, but the users still see the …

08.05.2024
Django login issue: Redirect to user panel not working despite status 200 in console [closed]

I'am building application in django and tailwind css to asking legal questions. I created user in django admin panel, created views etc. But after login(it is success 200 status), it doesn't work. I can't redirect user after login to user …

08.05.2024
DjangoAdmin render BinaryField as image

I wrote middleware to catch requests and view them on admin page. It successfully views raw text request body, but fails on image render. admin.py class RequestLogEntryAdmin(admin.ModelAdmin): fieldsets = ( ('Request', { 'fields': ('request_headers', 'request_size', 'request_body_'), }) ) def request_body_(self, …

08.05.2024
AutocompleteFilter must inherit from 'FieldListFilter'

I want to write custom filter with drop down field using admin_searchable_dropdown I tried two ways too implement this and got error both times first way: the custom filter class PrimaryLabelFilter(AutocompleteFilter): field_name = 'primary_label' title = …

08.05.2024
Git like view for dataframe comparison

I have two dataframe set called df1 and df2. I need to create a view in django template to compare these two dataframe in side by side. It should be looks like the git like comparison like below. <a href="https://i.sstatic.net/G3BWnWQE.png" …

08.05.2024
Weasyprint "Document has no attribute write_png"

I am writing a webapp in Python and Django. I use weasyprint to write pdf documents and I would like to use write_png() to get a png thumbnail of each pdf. This is from my views.py: pdf_letter = …

08.05.2024
'svc_payment_dev'. The domain name provided is not valid according to RFC 1034/1035

Upon sending requests to the dockerized Django app through the API gateway layer using the container name (svc_payment_dev), I faced an issue indicating that the domain name provided is not valid acoarding to RFC 1034/1035 I know that underscores are …

08.05.2024
Nginx and SSL configuration inside docker container is not working

Am using following nginx conf file : server { listen 80; server_name domain; # Redirect HTTP to HTTPS return 301 https://$host$request_uri; } server { listen 443 ssl; server_name localhost; ssl_certificate /etc/nginx/cert/ddomain.crt; ssl_certificate_key /etc/nginx/cert/domain.key; location / { proxy_pass http://0.0.0.0:8000; proxy_set_header Host …

08.05.2024
Nginx gives 403 Forbidden error serving files

I am a newbie to nginx and run into a problem: nginx response with 403 Forbidden when I request example.com/media/ and all files inside the media folder. I am creating web application with python using Django Rest Framework. Here is …

08.05.2024
DRF Forbidden (CSRF cookie not set.) from React axios POST request

As we know, we don't have access to Django CSRFToken in React by default, So we have to get it somehow. The solution was make a URL for receive CSRFToken in Response-Headers and set csrftoken cookie in browser. So I …

08.05.2024
Avoid app name appending in table name in django

I have implemented database routing in django. I am creating tables in two different database using database routing in django. The issue is app name is appended in database table name. I am using prosgreSql database. I tried to mention …

08.05.2024
Disable dark mode in bulma 1.0

I tried disabling the dark mode in my base.css like bulma describes in their docs by adding the @media lines: @media (prefers-color-scheme: light) { :root { } } body { display: flex; min-height: 100vh; flex-direction: column; } ... This …

08.05.2024
How to debug Okta SAML2 authentication issue in a React + Django application?

I'm integrating Okta SAML2 authentication into my React + Django application. However, despite not encountering any errors, when I attempt to access https://org.okta.com/app/org_lighthousedev_1/exk14dabkz9lmSTEq0x8/sso/saml, it redirects me to https://dev-lighthouse.corporate.org.com/accounts/login/?next=/sso/saml/ instead of completing the SAML authentication …

08.05.2024
How do i fix the Method not allowed (GET) error in django version 5 [duplicate]

I keep getting this error in logout.html in django everytime i go to it. Here is the code for the logout.html: &lt;form method=&quot;post&quot; action=&quot;{% url 'logout' %}&quot;&gt; {% csrf_token %} &lt;button type=&quot;submit&quot;&gt;logout&lt;/button&gt;&lt;/form&gt; here is my views.py code: from django.shortcuts import …

08.05.2024
Django settings not reflecting changes [closed]

I have a Django project running on an Ubuntu 22.04 server with Nginx and Gunicorn. After updating the project on my local server, I attempted to transfer it to my cloud server. Using FileZilla, I copied the new files to …

08.05.2024
How to add custom FileUploadHandler to request in ModelAdmin custom view Django 3.2

I need to add custom file upload handler in admin add and change view (using django 3.2). And getting an error. So far I created custom FileUploadHandler and trying to add to request in my ModelAdmin. Created class in my …

08.05.2024
Django rest framework Status 200 but 'Failed to Load Response Data" On jwt token api

This is the token api of drf jwt. It is giving me 200 but in response it is saying me failed to load data I tried the code in locally it is running in the postman and …

08.05.2024
Nginx + Django Static Files issue

I am having an issue with my project. I have everything working in my Django project, when the DEBUG=True in settings.py. But as soon as I change it to False, I get this issue when I go to my website …

08.05.2024
Django get() triggers FOUR queries [closed]

During deep debuging i found that simple .get triggers FOUR queries: kwargs['context']['user'] = models.Person.objects.get( pk=16879 ) And postgresql.log prints this: 2024-05-08 10:21:07.913 CEST [3987190] party@partytest LOG: statement: SELECT &quot;structure_persondata&quot;.&quot;id&quot;, &quot;structure_persondata&quot;.&quot;created_at&quot;, &quot;structure_persondata&quot;.&quot;updated_at&quot;, &quot;structure_persondata&quot;.&quot;person_id&quot;, &quot;structure_persondata&quot;.&quot;first_name&quot;, &quot;structure_persondata&quot;.&quot;middle_name&quot;, &quot;structure_persondata&quot;.&quot;last_name&quot;, &quot;structure_persondata&quot;.&quot;pesel&quot;, &quot;structure_persondata&quot;.&quot;validity_range&quot; FROM …

08.05.2024
Cannot get django-admin css file in "Django + nginx + docker"

I could not serve the Django-admin's static files... I think.. It can't not recognize the reverse-proxy path. the location /static/admin/ Literally, The Django static folder is in upstream django server. There is nginx.conf and the inside docker container with django. …

08.05.2024
Cannot resolved keyword 'date_created' into field

I have a problem with runserver on PowerShell. entries_detail.html: &lt;article&gt; &lt;h2&gt;{{ entry.date_created|date:'Y-m-d H:i' }}&lt;/h2&gt; &lt;h3&gt;{{ entry.title }}&lt;/h3&gt; &lt;p&gt;{{ entry.content }}&lt;/p&gt; &lt;/article&gt; entries_list.html: {% for entry in entry_list %} &lt;article&gt; &lt;h2 class=&quot;{{ entry.date_created|date:'l' }}&quot;&gt; {{ entry.date_created|date:'Y-m-d …

08.05.2024
How to connect to broker Websocket in django

I am building an algotrading platform, i have access to broker apis and websockets, but i dont know how to connect to broker websocket and consume the data on realtime basis in django I have setup channels: #consumers.py class ChatConsumer(WebsocketConsumer): …

08.05.2024
Why is django debug toolbar causing a 'ValueError at ... Another profiling tool is already active' error when Htmx ajax fires?

I had django-debug-toolbar working fine in my application until I added htmx. Now I'm getting Another profiling tool is already active error. The page loads then htmx fires on load …

08.05.2024
Docker-compose: Creating same container for different projects

I'm facing an issue with my Django projects that have a similar structure. Each project has a backend folder containing a docker-compose.yml and Dockerfile. The structure is as follows: project1/backend/docker-compose.yml project2.backend/docker-compose.yml The problem arises when I switch between projects …

08.05.2024
How to use Django AutocompleteFilter thtough 2 relations?

I have Django models hierarchy class Workspace(Model): title = CharField() class User(Model): workspace = ForeignKey(to=Workspace) class Chat(Model): user = ForeignKey(to=User) In Django admin at Chats page i want to filter them by workspace, but there are many workspaces, so …

08.05.2024
How to connect Django 5.0.3 to SQL Server database 2024 [duplicate]

I have been trying to connect Django with SQL server but there are errors occurring continuously no matter what I try. For example DATABASES = { 'default': { 'ENGINE': 'sql_server.pyodbc', 'NAME': 'xxxxx', 'USER': 'xxxx', 'PASSWORD': 'xxxx', 'HOST': 'xxxxx', 'PORT': '1433', …

08.05.2024
DJANGO ImportError: cannot import name 'url' from 'django.conf.urls' version 5.0.3 [duplicate]

I'm following this DJANGO Rest Framework tutorial: https://www.youtube.com/watch?v=eA4H3p95hbM&amp;list=PLmDLs7JbXWNjr5vyJhfGu69sowgIUl8z5&amp;index=4 After modifying in 'urls.py', then type &quot;python manage.py migrate&quot; I get this error: from django.conf.urls import url ImportError: cannot import name 'url' from 'django.conf.urls' (F:\Learning HTML and CSS\DJANGO_DAVE …

08.05.2024
His error originates from a subprocess, and is likely not a problem with pip

Pip install validate email Collecting validate Using cached validate-1.0.1.tar.gz (32 kB) Installing build dependencies ... done Getting requirements to build wheel ... error error: subprocess-exited-with-error × Getting requirements to build wheel did not run successfully. │ exit code: …

08.05.2024
Django Annotation: Convert time difference to whole number or decimal

I am trying to sum the hours user spent per day. I wanted to convert this into whole number or decimal (e.g. 2, 6.5) hrs, to easily plot this to my chart. But the result of below code is in …

08.05.2024
Use the Django ORM to do a left outer join between unrelated models?

Suppose I have two models: class One(models.Model): name = models.CharField(max_length=300, unique=True) class Two(models.Model): name = models.CharField(max_length=300, unique=True) They are not related by a foreign key, and there are reasons to leave it that way in this project. …

08.05.2024
How to deliver Django+Postgresql projects to clients?

I have been working on a project where my client wants me to load some csv files data into the database and he wants me to use Postgresql. The problem is that sqlite has a physical database stored in django …

07.05.2024
How do I expose information from Django model to the forms/views(?)/html(?) to be able to see all information built-in the model

I am trying to add more information to a form dropdown built using Django forms. A basic explanation of the program is: The user logs in The user can create 'decks' that are to be displayed on the 'game_tracking' …

07.05.2024
Users that will be using a django form and posting data

I have created a django web app with CRUD functionality, i want to be able to see the users (With their names) that have posted on the form and see a full list of the data they post along with …

07.05.2024
I have some errors while im trying to have a special number for each page in Django

I used int:observatory_id to provide a special number for each pages without any special typos and mistakes and i have this error Reverse for 'observatory' with arguments '('',)' not found. 1 pattern(s) tried: ['observatorys/(?P&lt;observatory_id&gt;[0-9]+)\Z'] here is my code : urls.py …

07.05.2024
Django - Removing subdomains from my multitenancy app

I have a working multitenancy app in Django with isolated databases that currently uses a subdomain for each tenant and threading. The subdomain prefix is used to make a connection to the corresponding database, so: client1.mysite.com access the database …

07.05.2024
How to set up DJANGO_SETTINGS_MODULE with absolute path of the settings.py file

I need to write some scripts for django and trying to set up the DJANGO_SETTINGS_MODULE environment variable at the beginning of each script. The scripts, manage.py and myproject directory are in the same parent directory. Additionally, settings.py file is in …

07.05.2024
Django: динамическое обновление списка в форме

Проблема с отображением списка в форме при выборе города: JavaScript и AJAX не обновляют содержимое. Как исправить? Есть функция по оформлению заказа (create_order), которая обрабатывает форму. В форме есть поле (country) - город. Задумка такая, хочу чтобы пользователь выбирал …

07.05.2024
How to make user in Django choose the workshop he added to make a service record for his own car?

Im struggling with same problem for 3 days now, im trying to make my finish project which is some kind of online servicebook for cars we own, i have models vehicle, workshop, filter, servicerecord and i cant add servicerecord to …