Generic views

Hi there, I am now in the genric views, and after implementing them I get an error saying:
module ‘polls/views’ has no atribute ‘index’
Note that polls/ used to have a function:
def index(parameter): ...
The tutorial asked to remove these function and subtitute them withblocks of code tha is charecerized with class.

I tried using the three backticks but didnt work, I dont know why

Carefully compare your and files to the ones specified here: Writing your first Django app, part 4 | Django documentation | Django. The error module 'polls/views' has no attribute 'index' means that the previous url path path('', views.index, name='index'), is erroring at the point of views.index because index isn’t a method in the file. This should be because you’ve replaced it with the class IndexView.

When I changed the urlpatterns to fit the views, now I am having error:
System check identified 4 errors.
On stack overflow it says the problem could from the database, but I dont know how to fix it

I do have a file called db.sqlite3
But when I ran the comand py dbshell I got: You appear not to have the ‘sqlite3’ program installed or on your path

Did you reactivate your virtual environment for the project before running dbshell?

I just did. That didnt help unfortunetly

These types of responses don’t allow for me/the community to help you. Please be specific about what you tried, what happened and what you expected to happen. This is in reference to the following messages:

If there is an exception, copy and paste the stacktrace and the full error message.

Yes you were right, I was not clear.
Before the error it asked me to write as_view() after each view urlspatterns in polls/urls
path('', views.IndexView.as_view(), name = 'IndexView'),

But now it is raising another error:
NoReverseMatch at /polls/ :
Reverse for ‘DetailView’ not found.
And it points to the link in the index.html template:

<a href = "{% url 'polls:detail' %}>{{ question.question_text }}

Thank you. The tutorial says to only change the view portion, not the names of the urls.

from django.urls import path

from . import views

app_name = 'polls'
urlpatterns = [
    path('', views.IndexView.as_view(), name='index'),
    path('<int:pk>/', views.DetailView.as_view(), name='detail'),
    path('<int:pk>/results/', views.ResultsView.as_view(), name='results'),
    path('<int:question_id>/vote/',, name='vote'),

Rather than:
path('', views.IndexView.as_view(), name = 'IndexView')
path('', views.IndexView.as_view(), name = 'index')

I’d suggest keeping in line with what the tutorial recommends as it makes future issues easier to solve. Once you change those, make sure you clean up any references in {% url polls: ... %} or reverse("polls: ...") calls.

1 Like

Thanks! That really heleped.
Maybe I should practice some patience next time