Search code examples
pythondjangowebserver

How can I fix errors on this page?


These errors occur when you enter the admin page. I want to fix this. Help me. problementer image description here

Source code

urls.py-fistsite

from django.contrib import admin
from django.urls import path, include
from polls import views

urlpatterns = [
    path('', views.index, name='index'),
    path('/polls', include('polls.urls')),
    path('/admin', include('polls.urls'))
]

urls.py-polls

from django.urls import path
from . import views


app_name = 'polls'
urlpatterns = [
    path('', views.index, name='index'),
    path('<int:question_id>/', views.detail, name='detail'),
    path('<int:question_id>/result/', views.results, name='results'),
    path('<int:question_id>/vote/', views.vote, name='vote')
]

Solution

  • Change your urls.py to this and it should work.

    urlpatterns = [
        path('polls/', include('polls.urls')),
        path('admin/', admin.site.urls), # add this
        path('', views.index, name='index'),
    ]
    

    For some reason you changed the site admin's url to include('polls.urls') which is incorrect. Change it back to path('admin/', admin.site.urls) and django will pick it up. And on the side note, You don't have to add / django has a middleware that does it automatically.