[Django]-Alternative to path() in Django 1.11

2👍

Just use url() instead of path()

from django.conf.urls import url, include
from django.contrib import admin

urlpatterns = [
    url(r'^admin', admin.site.urls),
    url(r'^moraimono/', include('moraimono.urls')),
]

Find more details in url documentation’s here

2👍

urlpatterns should be a list of url() instances. :

from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
    url(r'^index/$', index_view, name='main-view'),
    url(r'^moraimono/', include('moraimono.urls')),
    ...
]

url() is defined internally as:

def url(regex, view, kwargs=None, name=None):
    if isinstance(view, (list, tuple)):
        # For include(...) processing.
        urlconf_module, app_name, namespace = view
        return RegexURLResolver(regex, urlconf_module, kwargs, app_name=app_name, namespace=namespace)
    elif callable(view):
        return RegexURLPattern(regex, view, kwargs, name)
    else:
        raise TypeError('view must be a callable or a list/tuple in the case of include().')

0👍

use url, you already have it imported and in django 2.0 it’s synonymous with re_path

from django.conf.urls import url
from django.conf.urls import include
from django.contrib import admin

urlpatterns = [
    url(r'^'moraimono/$', include('moraimono.urls')),
    url(r'^'admin/$', admin.site.urls),
]

Leave a comment