# Djangorestframework compatibility with django

**URL:** <https://forum.djangoproject.com/t/djangorestframework-compatibility-with-django/10745>\
**Category:** Using Django\
**Created:** [November 30, 2021, 8:54pm UTC](https://forum.djangoproject.com/t/djangorestframework-compatibility-with-django/10745 "2021-11-30T20:54:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pmulgaonkar](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/pmulgaonkar/32/6496_2.png) [@pmulgaonkar](https://forum.djangoproject.com/u/pmulgaonkar)\
**Post date:** [November 30, 2021, 8:55pm UTC](https://forum.djangoproject.com/t/djangorestframework-compatibility-with-django/10745/1 "2021-11-30T20:55:00Z")

</div>

I am having difficulty upgrading an application from django 1.10 to django 2.2 (for a variety of reasons, I cannot go to django 3.x directly).

The current application runs fine and in its requirements.txt we specify django==1.10 and djangorestframework==3.5.3.

Upgrading to django==2.2, leaving the DRF where it is, results in an error being thrown from what apears to be a compatibility file that is installed in the virtual environment’s site-packages directory:

> File “/home/raxak/.virtualenvs/raxak/lib/python3.6/site-packages/rest\_framework/compat.py”, line 31, in   
> from django.core.urlresolvers import ( # Will be removed in Django 2.0

I have tried letting DRF installed it’s latest version but it has a different issue: It says that there is no module called report

> ModuleNotFoundError: No module named ‘report’

So is there a DRF version that works correctly with django==2.2 ?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [November 30, 2021, 9:04pm UTC](https://forum.djangoproject.com/t/djangorestframework-compatibility-with-django/10745/2 "2021-11-30T21:04:10Z")

</div>

The [requirements section of the docs](https://www.django-rest-framework.org/#requirements) imply that the current version is compatible with Django 2.2.

Without seeing the complete error message associated with this, it’s going to be tough to provide any firm guidance. There might be another third-party module involved here. You may want to scan your code for any import statement referencing a module with that name.

You also didn’t specify what version of Python you’re doing this with - that’s another component that will need to be brought forward as well.

---

<div class="post-metadata">

**Author:** ![adamchainz](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/adamchainz/32/26_2.png) [@adamchainz](https://forum.djangoproject.com/u/adamchainz)\
**Post date:** [November 30, 2021, 9:25pm UTC](https://forum.djangoproject.com/t/djangorestframework-compatibility-with-django/10745/3 "2021-11-30T21:25:03Z")

</div>

It’s best to upgrade Django one version at a time: from 1.10 to 1.11, then 1.11 to 2.0, etc. This is in the docs: [Upgrading Django to a newer version | Django documentation | Django](https://docs.djangoproject.com/en/3.2/howto/upgrade-version/) . This way you can ensure you aren’t missing any deprecation notices that were added for only a few versions. It doesn’t take too long when you get into the swing of it.

If you’re seeing compat problems with a library like DRF, read through its changelog to figure out which versions are compatible with the django version you’re on. DRF in particular lists the version compat in its announcements: [3.9 Announcement - Django REST framework](https://www.django-rest-framework.org/community/3.9-announcement/#supported-versions)

---

<div class="post-metadata">

**Author:** ![pmulgaonkar](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/pmulgaonkar/32/6496_2.png) [@pmulgaonkar](https://forum.djangoproject.com/u/pmulgaonkar)\
**Post date:** [November 30, 2021, 9:59pm UTC](https://forum.djangoproject.com/t/djangorestframework-compatibility-with-django/10745/4 "2021-11-30T21:59:50Z")

</div>

I am using python3.6 in a virtual environment.

The complete error trace is:

> (raxak) [raxak@centos8 raxak]$ python3 manage.py test  
> Traceback (most recent call last):  
> File “/home/raxak/.virtualenvs/raxak/lib/python3.6/site-packages/rest\_framework/compat.py”, line 27, in   
> from django.urls import (  
> ImportError: cannot import name ‘RegexURLPattern’
> 
> During handling of the above exception, another exception occurred:
> 
> Traceback (most recent call last):  
> File “manage.py”, line 22, in   
> execute\_from\_command\_line(sys.argv)  
> File “/home/raxak/.virtualenvs/raxak/lib/python3.6/site-packages/django/core/management/ **init**.py”, line 381, in execute\_from\_command\_line  
> utility.execute()  
> File “/home/raxak/.virtualenvs/raxak/lib/python3.6/site-packages/django/core/management/ **init**.py”, line 375, in execute  
> self.fetch\_command(subcommand).run\_from\_argv(self.argv)  
> File “/home/raxak/.virtualenvs/raxak/lib/python3.6/site-packages/django/core/management/commands/test.py”, line 23, in run\_from\_argv  
> super().run\_from\_argv(argv)  
> File “/home/raxak/.virtualenvs/raxak/lib/python3.6/site-packages/django/core/management/base.py”, line 323, in run\_from\_argv  
> self.execute(\*args, \*\*cmd\_options)  
> File “/home/raxak/.virtualenvs/raxak/lib/python3.6/site-packages/django/core/management/base.py”, line 364, in execute  
> output = self.handle(\*args, \*\*options)  
> File “/home/raxak/.virtualenvs/raxak/lib/python3.6/site-packages/django/core/management/commands/test.py”, line 53, in handle  
> failures = test\_runner.run\_tests(test\_labels)  
> File “/home/raxak/.virtualenvs/raxak/lib/python3.6/site-packages/django/test/runner.py”, line 632, in run\_tests  
> self.run\_checks()  
> File “/home/raxak/.virtualenvs/raxak/lib/python3.6/site-packages/django/test/runner.py”, line 570, in run\_checks  
> call\_command(‘check’, verbosity=self.verbosity)  
> File “/home/raxak/.virtualenvs/raxak/lib/python3.6/site-packages/django/core/management/ **init**.py”, line 148, in call\_command  
> return command.execute(\*args, \*\*defaults)  
> File “/home/raxak/.virtualenvs/raxak/lib/python3.6/site-packages/django/core/management/base.py”, line 364, in execute  
> output = self.handle(\*args, \*\*options)  
> File “/home/raxak/.virtualenvs/raxak/lib/python3.6/site-packages/django/core/management/commands/check.py”, line 64, in handle  
> fail\_level=getattr(checks, options[‘fail\_level’]),  
> File “/home/raxak/.virtualenvs/raxak/lib/python3.6/site-packages/django/core/management/base.py”, line 390, in check  
> include\_deployment\_checks=include\_deployment\_checks,  
> File “/home/raxak/.virtualenvs/raxak/lib/python3.6/site-packages/django/core/management/base.py”, line 377, in \_run\_checks  
> return checks.run\_checks(\*\*kwargs)  
> File “/home/raxak/.virtualenvs/raxak/lib/python3.6/site-packages/django/core/checks/registry.py”, line 72, in run\_checks  
> new\_errors = check(app\_configs=app\_configs)  
> File “/home/raxak/.virtualenvs/raxak/lib/python3.6/site-packages/django/core/checks/urls.py”, line 13, in check\_url\_config  
> return check\_resolver(resolver)  
> File “/home/raxak/.virtualenvs/raxak/lib/python3.6/site-packages/django/core/checks/urls.py”, line 23, in check\_resolver  
> return check\_method()  
> File “/home/raxak/.virtualenvs/raxak/lib/python3.6/site-packages/django/urls/resolvers.py”, line 398, in check  
> for pattern in self.url\_patterns:  
> File “/home/raxak/.virtualenvs/raxak/lib/python3.6/site-packages/django/utils/functional.py”, line 80, in **get**  
> res = instance. **dict** [self.name] = self.func(instance)  
> File “/home/raxak/.virtualenvs/raxak/lib/python3.6/site-packages/django/urls/resolvers.py”, line 571, in url\_patterns  
> patterns = getattr(self.urlconf\_module, “urlpatterns”, self.urlconf\_module)  
> File “/home/raxak/.virtualenvs/raxak/lib/python3.6/site-packages/django/utils/functional.py”, line 80, in **get**  
> res = instance. **dict** [self.name] = self.func(instance)  
> File “/home/raxak/.virtualenvs/raxak/lib/python3.6/site-packages/django/urls/resolvers.py”, line 564, in urlconf\_module  
> return import\_module(self.urlconf\_name)  
> File “/usr/lib64/python3.6/importlib/ **init**.py”, line 126, in import\_module  
> return \_bootstrap.\_gcd\_import(name[level:], package, level)  
> File “”, line 994, in \_gcd\_import  
> File “”, line 971, in \_find\_and\_load  
> File “”, line 955, in \_find\_and\_load\_unlocked  
> File “”, line 665, in \_load\_unlocked  
> File “”, line 678, in exec\_module  
> File “”, line 219, in \_call\_with\_frames\_removed  
> File “/u01/rp/raxak/raxakprotect/urls.py”, line 22, in   
> from users.views import RaxakManage, Terms  
> File “/u01/rp/raxak/users/views.py”, line 20, in   
> from rest\_framework import viewsets, renderers  
> File “/home/raxak/.virtualenvs/raxak/lib/python3.6/site-packages/rest\_framework/viewsets.py”, line 26, in   
> from rest\_framework import generics, mixins, views  
> File “/home/raxak/.virtualenvs/raxak/lib/python3.6/site-packages/rest\_framework/generics.py”, line 10, in   
> from rest\_framework import mixins, views  
> File “/home/raxak/.virtualenvs/raxak/lib/python3.6/site-packages/rest\_framework/mixins.py”, line 10, in   
> from rest\_framework.response import Response  
> File “/home/raxak/.virtualenvs/raxak/lib/python3.6/site-packages/rest\_framework/response.py”, line 13, in   
> from rest\_framework.serializers import Serializer  
> File “/home/raxak/.virtualenvs/raxak/lib/python3.6/site-packages/rest\_framework/serializers.py”, line 30, in   
> from rest\_framework.compat import JSONField as ModelJSONField  
> File “/home/raxak/.virtualenvs/raxak/lib/python3.6/site-packages/rest\_framework/compat.py”, line 31, in   
> from django.core.urlresolvers import ( # Will be removed in Django 2.0  
> ModuleNotFoundError: No module named ‘django.core.urlresolvers’

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [November 30, 2021, 11:08pm UTC](https://forum.djangoproject.com/t/djangorestframework-compatibility-with-django/10745/5 "2021-11-30T23:08:12Z")

</div>

Sorry, I wasn’t clear. That appears to be the problem you mentioned when you were trying to upgrade Django while using the old DRF. I thought you reported a different problem when you upgraded DRF - that’s what I thought we were trying to address.
