ruffen
ruffen

Reputation: 1719

import urlresolvers from django.core in django 2 after upgrading from django 1

trying to import:

from django.core import urlresolvers

I get:

ImportError: cannot import name 'urlresolvers' from 'django.core' 

This is because UrlResolvers are deprecated and replaced with Django.Url. However I am looking for the actual UrlResolvers in order to find:

urlresolvers.get_resolver(None)

I cant find where this method has gone in the documentation.

Using Latest django and Python 3.7 now.

Upvotes: 0

Views: 1747

Answers (2)

rchurch4
rchurch4

Reputation: 899

django.core.urlresolvers no longer exists in Django 2.0. Instead, you can find it in django.urls.

Upvotes: 1

markwalker_
markwalker_

Reputation: 12869

Django 2 changes the URLs, you can from django.urls import path, get_resolver etc.

From the django docs, to clarify the basic URL setup;

from django.urls import get_resolver

get_resolver(None)

https://docs.djangoproject.com/en/2.1/topics/http/urls/

The source is here for the resolvers; https://docs.djangoproject.com/en/2.1/_modules/django/urls/resolvers/

Upvotes: 1

Related Questions