rpjs
rpjs

Reputation: 309

DRF - from django.conf.urls import url in Django 4.0

I've a project in django 3.2 and I've updated (pip install -r requirements.txt) to version 4.0 (new release) and I've currently the below error when I run the server in a virtual environment. I use DRF.

Can't import => from rest_framework import routers in urls.py

from django.conf.urls import url ImportError: cannot import name 'url' from 'django.conf.urls'

Upvotes: 5

Views: 1780

Answers (1)

Kaushal Sharma
Kaushal Sharma

Reputation: 2300

As per the Django docs here:

url(regex, view, kwargs=None, name=None)¶ This function is an alias to django.urls.re_path().

Deprecated since version 3.1: Alias of django.urls.re_path() for backwards compatibility.

django.conf.urls.url() was deprecated since Django 3.1, and as per the release notes here, is removed in Django 4.0+.

You can resolve the issue using path or re_path.

https://docs.djangoproject.com/en/4.0/ref/urls/

Upvotes: 2

Related Questions