# Writing your first Django app, part 4

I create vote app from django

Writing your first Django app, part 4

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/", views.vote, name="vote"),
]

after that code errors with

File “”, line 1387, in _gcd_import
File “”, line 1360, in _find_and_load
File “”, line 1331, in _find_and_load_unlocked
File “”, line 935, in _load_unlocked
File “”, line 995, in exec_module
File “”, line 488, in _call_with_frames_removed
File “C:\Users\Baxti\Desktop\django-app\polls\urls.py”, line 3, in
from . import views
File “C:\Users\Baxti\Desktop\django-app\polls\views.py”, line 5
from django.views import generic,
^
SyntaxError: trailing comma not allowed without surrounding parentheses

another Error why
File “”, line 1387, in _gcd_import
File “”, line 1360, in _find_and_load
File “”, line 1331, in _find_and_load_unlocked
File “”, line 935, in _load_unlocked
File “”, line 995, in exec_module
File “”, line 488, in _call_with_frames_removed
File “C:\Users\Baxti\Desktop\django-app\polls\urls.py”, line 9, in
path(“”, views.IndexView.as_view(), name=“index”),
^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: ‘function’ object has no attribute ‘as_view’

Hi, (Assalomu aleykum)

It seems the error is in your views.py, specifically in line 5. While importing, make sure there is no comma at the end of the line. You need to remove that comma from line 5:

from django.views import generic

The second error means, in short, this:
You cannot use as_view attribute for a function-based view, i.e. they are only for class-based views. Looking at your traceback, you can try removing .as_view() from your IndexView:

path(“”, views.IndexView, name=“index”),

Opinion Part
The official polls tutorial is famously not for those new to Django. You may find Django for Beginners or LearnDjango.com very useful. Then, the polls tutorial will be very beneficial.

1 Like

need your views.py code.

1 Like

thanks I found issue