On Thursday, December 5, 2024 at 1:02:36 PM UTC+1 Олександр Рябов wrote:
Hello! I'm facing an issue when running my Django project. I get the following error:
AttributeError: module 'polls.views' has no attribute 'index'
I've checked the following:1) In "polls/views.py", I have defined the index function:from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, World!")
2) In polls/urls.py, the path to this function is correctly defined:
from django.urls import path, include
from . import views
urlpatterns = [
path("", views.index, name="index"),
]
3) In the main mysite/urls.py, the URLs from polls are included:
from django.contrib import adminfrom django.urls import include, path
urlpatterns = [
path("polls/", include("polls.urls")),
path("admin/", admin.site.urls),
]
However, when I run the server with the command:
" python manage.py runserver "I get the error mentioned above. I have also made sure that all imports are correct and that the project is using the right Python version.
What could be the cause of this error and how can I fix it? Thank you!
P.S.
- I am writing my code in Visual Studio Code and have attached two pictures for reference.
- The first picture shows the general structure of my project.
- The second picture displays the full error message from the command line(*try to enlarge it, I hope you can see everything.)
#1
#2
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/django-users/3ac25773-c449-444e-9d69-d20f23af18cdn%40googlegroups.com.
No comments:
Post a Comment