Reputation: 133
I just learned Django, I'm following the 'Writing your first Django app' from the website. But when I come to the Django Admin part, I got an error.
TypeError at /admin/
'set' object is not reversible
Request Method: GET
Request URL: http://localhost:8000/admin/
Django Version: 3.0.2
Exception Type: TypeError
Exception Value:
'set' object is not reversible
Exception Location: D:\python\lib\site-packages\django\urls\resolvers.py in _populate, line 455
Python Executable: D:\python\python.exe
Python Version: 3.8.1
Python Path:
['D:\\python\\projek\\mysite',
'D:\\python\\python38.zip',
'D:\\python\\DLLs',
'D:\\python\\lib',
'D:\\python',
'D:\\python\\lib\\site-packages']
Server time: Sat, 1 Feb 2020 08:37:20 +0000
I realize that the error comes when I add new path to the urls.py file as the tutorial told.
Here is my urls.py code
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('polls/', include('polls.urls')), <<---- This is the problem
path('admin/', admin.site.urls),
]
here is my polls/urls.py
from django.urls import path
from . import views
urlpatterns = {
# ex: /polls/
path('', views.index, name='index'),
# ex: /polls/5/
path('<int:question_id>/', views.detail, name='detail'),
# ex: /polls/5/results/
path('<int:question_id>/results/', views.results, name='results'),
# ex: /polls/5/vote/
path('<int:question_id>/vote/', views.vote, name='vote'),
}
When I add the polls path the error comes, but when I comment that line the app work.
What's wrong with my code?
Upvotes: 2
Views: 591
Reputation: 3392
change your url pattern to
urlpatterns = [
# ex: /polls/
path('', views.index, name='index'),
# ex: /polls/5/
path('<int:question_id>/detail/', views.detail, name='detail'),
# ex: /polls/5/results/
path('<int:question_id>/results/', views.results, name='results'),
# ex: /polls/5/vote/
path('<int:question_id>/vote/', views.vote, name='vote'),
]
Instead of curly brackets you have to use square brackets and make pattern in such a way that it should not overlap
Upvotes: 2