I am working through chapter 18 in Python Crash Course by Eric Matthes, which is a tutorial on how to create web apps with Django. Currently I'm mapping a URL, writing a view, writing a template, and then trying to deploy the app on my system so I can see the homepage I created.
Here are the relevant files/code:
urls.py-learning_log
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('learning_logs.urls'))
]
urls.py-learning_logs
"""Defines URL patterns for learning_logs."""
from django.urls import path
from . import views
app_name = 'learning_logs'
url_patterns = [
# Home page
path('', views.index, name='index'),
]
views.py
from django.shortcuts import render
def index(request):
"""The home page for Learning Log."""
return render(request, 'learning_logs/index.html')
index.html
<p>Learning Log</p>
<p>Learning Log helps you to keep track of your learning, for any topic you're learning about.</p>
When I try to create the server using the runserver
command from within the virtual environment for the project using Powershell for Windows, here's the error I get:
(ll_env) PS C:\Users\Samie\Desktop\python_work\learning_log> python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Users\Samie\Desktop\python_work\learning_log\ll_env\lib\site-
packages\django\urls\resolvers.py", line 590, in url_patterns
iter(patterns)
TypeError: 'module' object is not iterable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Samie\AppData\Local\Programs\Python\Python38-32\lib\threading.py", line 932, in
_bootstrap_inner
self.run()
File "C:\Users\Samie\AppData\Local\Programs\Python\Python38-32\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\Samie\Desktop\python_work\learning_log\ll_env\lib\site-
packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\Samie\Desktop\python_work\learning_log\ll_env\lib\site-
packages\django\core\management\commands\runserver.py", line 117, in inner_run
self.check(display_num_errors=True)
File "C:\Users\Samie\Desktop\python_work\learning_log\ll_env\lib\site-
packages\django\core\management\base.py", line 392, in check
all_issues = self._run_checks(
File "C:\Users\Samie\Desktop\python_work\learning_log\ll_env\lib\site-
packages\django\core\management\base.py", line 382, in _run_checks
return checks.run_checks(**kwargs)
File "C:\Users\Samie\Desktop\python_work\learning_log\ll_env\lib\site-
packages\django\core\checks\registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Users\Samie\Desktop\python_work\learning_log\ll_env\lib\site-
packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "C:\Users\Samie\Desktop\python_work\learning_log\ll_env\lib\site-
packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "C:\Users\Samie\Desktop\python_work\learning_log\ll_env\lib\site-
packages\django\urls\resolvers.py", line 408, in check
messages.extend(check_resolver(pattern))
File "C:\Users\Samie\Desktop\python_work\learning_log\ll_env\lib\site-
packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "C:\Users\Samie\Desktop\python_work\learning_log\ll_env\lib\site-
packages\django\urls\resolvers.py", line 407, in check
for pattern in self.url_patterns:
File "C:\Users\Samie\Desktop\python_work\learning_log\ll_env\lib\site-
packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\Samie\Desktop\python_work\learning_log\ll_env\lib\site-
packages\django\urls\resolvers.py", line 597, in url_patterns
raise ImproperlyConfigured(msg.format(name=self.urlconf_name))
django.core.exceptions.ImproperlyConfigured: The included URLconf '<module 'learning_logs.urls' from
'C:\\Users\\Samie\\Desktop\\python_work\\learning_log\\learning_logs\\urls.py'>' does not appear to
have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a
circular import.
That's quite a lot for me to digest as a super green Python/Django user. Can anybody see where I am going wrong here? I know that the version of Django I have installed for this project is newer than when the book was published (2019), can that be the issue? Thank you for any help provided!
The problem is in your urls.py-learning_logs. You misspelled urlpatterns as the name of the list. The spelling should be exactly urlpatterns. Hence the error ... does not appear to have any patterns in it...
Just change url_patterns to urlpatterns
"""Defines URL patterns for learning_logs."""
from django.urls import path
from . import views
urlpatterns = [
# Home page
path('', views.index, name='index'),
]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.