Home > Software design >  How to configure BaseURL in Django4?
How to configure BaseURL in Django4?

Time:12-22

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?

CodePudding user response:

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),
            ]
        ),
    ),
]

  • Related