[Fixed]-Django NameError: name 'views' is not defined

35👍

The error line is

    url(r'^$', views.index, name='index'),
    #----------^

Here views is not defined, hence the error. You need to import it from your app.

in urls.py add line

from <your_app> import views
# replace <your_app> with your application name.
👤Rohan

1👍

from .views import index
  • here we have to import views model classes on urls model so above sentence import your view model class on urls model.

add this code in urls.py

0👍

If you are using rest_framework in django then import:

from rest_framework import views

Leave a comment