How to configure BaseURL in Django4?

Question:

I’m new to django and trying to set a baseURL in django4. I came upon How to set base URL in Django of which the solution is:

from django.conf.urls import include, url
from . import views

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

but this import statement:

from django.conf.urls import url

shows:

Cannot find reference 'url' in '__init__.py' 

What am I doing wrong?

Answers:

django.conf.urls has been replaced by django.urls (actually back in Django 2.0, in 2017), and url is re_path these days. However, if you don’t need a regexp route, just use path:

from django.urls import include, path
from . import views

urlpatterns = [
    path(
        "someuri/",
        include(
            [
                path("admin/", include(admin.site.urls)),
                path("other/", views.other),
            ]
        ),
    ),
]

Answered By: AKX
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.