thomasw / djproxy

djproxy is a class-based generic view reverse HTTP proxy for Django.
MIT License
42 stars 15 forks source link

url() is deprecated in Django 3.1+ #38

Open coofercat opened 3 years ago

coofercat commented 3 years ago

For anyone else looking for how to make this work in Django 3.1+, you'll find that url() is deprecated, so where you see this in the documentation:

url(r'^local_proxy/(?P<url>.*)$', LocalProxy.as_view(), name='proxy')

...change it to this:

path('local_proxy/<path:url>', views.LocalProxy.as_view(), name='proxy'),

(you could also use re_path(), but there's really no need)

I hope this helps someone out :-)

thomasw commented 3 years ago

Thanks. We need to drop unsupported django versions to fully resolve the confusion (which will let us remove url() entirely from docs, samples).

I'll leave this open for visibility until that happens.

FabienArcellier commented 2 years ago

I have proposed a way to maintain the compatibility and using re_path instead of url. We can maintain compatibility with older version of django

# The django url function is deprecated as of django 3.1
# We use its equivalent re_path to maintain compatibility
# with older versions of django
try:
    from django.urls import re_path
except ImportError as exception:
    from django.conf.urls import url as re_path

Here is the PR : https://github.com/thomasw/djproxy/pull/43.