Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New url format in Django 1.9

Tags:

I recently upgraded my Django project to version 1.9.

When I try to run migrate, I am getting the following two errors:

  1. Support for string view arguments to url() is deprecated and will be removed in Django 1.10 (got app.views.about). Pass the callable instead.
  2. django.conf.urls.patterns() is deprecated and will be removed in Django 1.10. Update your urlpatterns to be a list of django.conf.urls.url() instances instead.

Could someone please show me the proper syntax of how to do this? A brief sample of my urls.py is below:

urlpatterns = patterns('',
    url(r'^about/$', 'app.views.about',
        name='about'),
)

urlpatterns += patterns('accounts.views',
    url(r'^signin/$', 'auth_login',
        name='login'),
)

Thank you!

like image 804
jape Avatar asked Dec 05 '15 17:12

jape


People also ask

Is url deprecated in Django?

Yes, if they upgrade to django-4.0, url will no longer be available.

How do I reference a url in Django?

Django offers a way to name urls so it's easy to reference them in view methods and templates. The most basic technique to name Django urls is to add the name attribute to url definitions in urls.py .

What is Re_path in Django?

re_path is a callable within the django. urls module of the Django project.


1 Answers

Import your views directly, or your views modules:

from apps.views import about
from accounts import views as account_views

Do not use patterns at all, just use a list or tuple:

urlpatterns = [
    url(r'^about/$', about,
        name='about'),
]

urlpatterns += [
    url(r'^signin/$', account_views.auth_login,
        name='login'),
]
like image 137
Lorenzo Peña Avatar answered Oct 12 '22 23:10

Lorenzo Peña