Django 1.4 urls.py deprecated, urlpatterns to change

14 views
Skip to first unread message

Mdlr

unread,
Nov 8, 2019, 5:48:32 PM11/8/19
to Django users

I try to compile an old code in Django 1.4 Many things are deprecated. I manage to change some of them but I don't knwo how to go futher on the urls.py

here is the old code


from django.conf.urls.defaults import *
from django.conf import settings

dynurls = patterns('minesweepr.views',
    (r'^api/minesweeper_solve/$', 'api_solve'),
)

staticurls = patterns('minesweepr.views',
    (r'^player/$', 'template_static'),
    (r'^query/$', 'template_static'),
)

urlpatterns = patterns('',
    ('^%s' % settings.BASE_URL, include(dynurls)),
    ('^%s' % settings.BASE_STATIC_URL, include(staticurls)),            
)



I know django.conf.urls.defaults is deprecated and I tried to change the code like this



from django.conf.urls import url, include from django.conf import settings dynurls = ['minesweepr.views', (r'^api/minesweeper_solve/$', 'api_solve'), ] staticurls = ['minesweepr.views', (r'^player/$', 'template_static'), (r'^query/$', 'template_static'), ] urlpatterns = ['', ('^%s' % settings.BASE_URL, include(dynurls)), ('^%s' % settings.BASE_STATIC_URL, include(staticurls)), ]

But it is not sufficient It is said my url patterns are invalid. Anybody has an idea ? Thank you

Motaz Hejaze

unread,
Nov 9, 2019, 3:51:44 AM11/9/19
to django...@googlegroups.com
You can use path or re_path
 path for normal urls
 re_path for urls containing regular expressions 

urlpatterns = [

path('index' , views.index , name='index)

re_path('index/[a-z]*w/' , views.another_index , name='anotherIndex')



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f5ff4194-ae39-4020-ab80-9373ea19d15a%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages