David542
David542

Reputation: 110163

How to do urlconf in django 2.0+

I have created a view at example.views.py, and here is my urls.py file:

from django.urls import path

urlpatterns = [
    path('/', example.views.index, name='index'),
]

However, when I run django's runserver, I get the following error:

path('/', example.views.index, name='index'),
NameError: name 'example' is not defined

What do I need to do to fix this? Quoting the view doesn't help either.

Upvotes: 1

Views: 92

Answers (1)

Sazzy
Sazzy

Reputation: 1994

Try changing it to:

from django.urls import path
from example import views

urlpatterns = [
    path('/', views.index, name='index'),
]

Upvotes: 1

Related Questions