Questions tagged [django-4.0]

Django 4.0 is a version of the Django framework, released in December 2021. Please only use this tag if your question relates specifically to this version.

Django 4.0 works with Python 3.8, 3.9, and 3.10.

Here are some of the salient features of Django 4.0:

Django 4.0 was released in December 2021 and was supported until April 2023.

88 questions
157
votes
5 answers

ImportError: cannot import name 'url' from 'django.conf.urls' after upgrading to Django 4.0

After upgrading to Django 4.0, I get the following error when running python manage.py runserver ... File "/path/to/myproject/myproject/urls.py", line 16, in from django.conf.urls import url ImportError: cannot import name 'url'…
Alasdair
  • 298,606
  • 55
  • 578
  • 516
8
votes
1 answer

Django4.0 ImportError: cannot import name 'ugettext_lazy' from 'django.utils.translation'

I use translation in my Django apps. Since I installed Django version 4, when I try to import ugettexget_lazy as shown in the code below from django.utils.translation import ugettexget_lazy as _ I get the following error: ImportError: cannot import…
Gedeon Mutshipayi
  • 2,871
  • 3
  • 21
  • 42
5
votes
1 answer

Too many db connections (django 4.x / ASGI)

I have deployed a django app (on ASGI using uvicorn) and getting a lot of OperationalError FATAL: sorry, too many clients already It seems that this is a known issue #33497 for django 4.x and ASGI, but I cant find anything on it (other than…
fekioh
  • 894
  • 2
  • 9
  • 22
5
votes
2 answers

Cannot import is_safe_url from django.utils.http , alternatives?

I am trying to update my code to the latest Django version, The method is_safe_url() seems to be removed from new version of Django (4.0). I have been looking for an alternative for the past few hours with no luck. Does anyone know of any…
p.ry
  • 409
  • 1
  • 8
  • 21
5
votes
1 answer

Django 4 Pycharm debugger error: can't find '__main__' module in ''

My Django project is working properly when I am pressing pycharm's green play button. But when debug button is clicked, it says can't find '__main__' module in ''. I did little bit RCA and found __spec__ is being set on __main__ when running with…
4
votes
3 answers

I have an error about smart_text after installing django-admin-charts

I want to have charts in the admin panel, I installed the django-admin-charts package, Which said add these to settings.py INSTALLED_APPS = ( 'admin_tools_stats', # this must be BEFORE 'admin_tools' and 'django.contrib.admin' …
user18556740
  • 57
  • 1
  • 4
4
votes
2 answers

Django How to check a request is Ajax

The HttpRequest.is_ajax() method is deprecated as it relied on a jQuery-specific way of signifying AJAX calls, while current usage tends to use the JavaScript Fetch API. Depending on your use case, you can either write your own AJAX detection method…
Ayaz Ur Rashid
  • 221
  • 3
  • 9
3
votes
1 answer

How to access context from a custom django-admin command?

I have been using django.text client to examine the context of some URLs from several unit tests with a code similar to the following: from django.test import TestCase class MyTests(TestCase): def example_test(self): …
Alfonso_MA
  • 537
  • 5
  • 26
3
votes
1 answer

DigitalOcean Droplet not serving django app with python runserver command

i know i have seen similar questions on the issue but most of them seemed to be solved by allowing the port 8000 by using the command sudo ufw allow 8000. i have tried that but it is still not displaying when i visited my droplet_ipaddress:8000…
Brian Obot
  • 336
  • 4
  • 16
3
votes
4 answers

Django 4 connection to Postgresql using passfile: "fe_sendauth: no password supplied"

Hello SO & Django community, My problem is related to Django 4, as the feature to use passfile to connect to Postgres has appeared in this version. Though I have went through the similar error message related questions about previous versions, I had…
awb-ox
  • 33
  • 2
  • 6
3
votes
0 answers

Django How to UPDATE ... RETURNING

In Postgresql you can issue an UPDATE with a RETURNING statement in order to fetch some columns after you perform an update. This is useful because you can do this in one trip to the database instead of two. UPDATE foo SET bar = 10 WHERE id =…
Matthew Moisen
  • 16,701
  • 27
  • 128
  • 231
2
votes
1 answer

The model User is not registered (django-4 admin.py)

I'm trying to give User (django's default, not custom model) an Address in the admin view. I am working for the first time with different versions of django in different projects, I do the same in Django 2 and it works, and here I use Django 4. This…
Vicente
  • 31
  • 4
2
votes
1 answer

Add extra property to this json response returned by Django rest framework

I am running django 4.0.6 with djangorestframework. This is my serializers.py from django.contrib.auth import get_user_model from rest_framework import serializers class UserSerializer(serializers.ModelSerializer): # new class Meta: …
user3848207
  • 3,737
  • 17
  • 59
  • 104
2
votes
1 answer

Django 4 update form fields dynamically using HTMX

I developed a Django application in which i have a form with some fields. Depending on the input additional fields are displayed are hidden. Now everything worked quit fine in Django 3.2.14 since the update in Django 4.0.6 it didn't worked…
David Marogy
  • 116
  • 7
2
votes
1 answer

1054, "Unknown column" exception upon adding nonexisting field in Django 4.0

I have struck upon a problem of adding additional field. I want it to be boolean, but it doesn't actually matter which type the field will be, because I also tried to create an integer field instead of boolean with getting the same exception. The…
Plan SK
  • 21
  • 1
  • 3
1
2 3 4 5 6