Sunday, July 25, 2021

Re: AttributeError: module 'polls.views' has no attribute 'index'

Had the same issue.

Solved, make sure you run each edited python file during the tutorial.
I guess it needs to update. All I know is this fixed the issue.

On Monday, April 19, 2021 at 2:07:34 AM UTC+10 avi.me...@gmail.com wrote:
I followed the same tutorial on 17th April 2021 with Python 3.9.2 and Django     3.2 and have exactly the same problems as mentioned above.

    path('', views.index, name='index'),

AttributeError: module 'polls.views' has no attribute 'index'

any help on how can I debug this? I am a django noob

On Wednesday, 19 April 2017 at 16:31:59 UTC+2 lce...@gmail.com wrote:
Thanks for your reploy.

Actually I followed the tutorial exactly.

My polls/views.py has:

from django.http import HttpResponse


def index(request):
    return HttpResponse("Hello, world. You're at the polls index.")

My polls/urls.py has:

from django.conf.urls import url

from . import views

urlpatterns = [
    url(r'^$', views.index, name='index'),
]


On Wednesday, 19 April 2017 15:43:57 UTC+2, m712 - Developer wrote:

You didn't give us enough info, but I am thinking that you don't have an index() function in your polls/views.py. Start the tutorial from the beginning and follow it closely.

On Apr 19, 2017 4:17 PM, Billy Lin <lce...@gmail.com> wrote:
I'm following the getting started tutorial 01 and running into issues after creating the polls app. Can someone please help?

I'm using Python 3.6.1 and Django 1.11.

Here's the detailed trace:

Performing system checks...
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x04222810>
Traceback (most recent call last):
  File "C:\Users\cephalin\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\autoreload.py", line
227, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\cephalin\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\commands\ru
nserver.py", line 125, in inner_run
    self.check(display_num_errors=True)
  File "C:\Users\cephalin\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\base.py", l
ine 359, in check
    include_deployment_checks=include_deployment_checks,
  File "C:\Users\cephalin\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\base.py", l
ine 346, in _run_checks
    return checks.run_checks(**kwargs)
  File "C:\Users\cephalin\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\checks\registry.py", l
ine 81, in run_checks
    new_errors = check(app_configs=app_configs)
  File "C:\Users\cephalin\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\checks\urls.py", line
16, in check_url_config
    return check_resolver(resolver)
  File "C:\Users\cephalin\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\checks\urls.py", line
26, in check_resolver
    return check_method()
  File "C:\Users\cephalin\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\urls\resolvers.py", line 25
4, in check
    for pattern in self.url_patterns:
  File "C:\Users\cephalin\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\functional.py", line
35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\cephalin\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\urls\resolvers.py", line 40
5, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "C:\Users\cephalin\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\functional.py", line
35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\cephalin\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\urls\resolvers.py", line 39
8, in urlconf_module
    return import_module(self.urlconf_name)
  File "C:\Users\cephalin\AppData\Local\Programs\Python\Python36-32\lib\importlib\__init__.py", line 126, in import_modu
le
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
  File "C:\Users\cephalin\Repos\django\mysite\mysite\urls.py", line 20, in <module>
    url(r'^polls/', include('polls.urls')),
  File "C:\Users\cephalin\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\conf\urls\__init__.py", lin
e 50, in include
    urlconf_module = import_module(urlconf_module)
  File "C:\Users\cephalin\AppData\Local\Programs\Python\Python36-32\lib\importlib\__init__.py", line 126, in import_modu
le
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
  File "C:\Users\cephalin\Repos\django\mysite\polls\urls.py", line 6, in <module>
    url(r'^$', views.index, name='index'),
AttributeError: module 'polls.views' has no attribute 'index'

--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b77a1a74-b07f-4277-98da-23b46ca7d2e4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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 on the web visit https://groups.google.com/d/msgid/django-users/cc9b3670-d625-4505-91a1-fe63041c1ae3n%40googlegroups.com.

No comments:

Post a Comment