Python Forum
Stuck on Chapter 19 Python Crash Course with error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Stuck on Chapter 19 Python Crash Course with error
#1
Hello, I'm getting the following error when trying to runserver to work through chapter 19 - user accounts. I have used the updates on the Crash Course Site but still cannot figure out where this error is coming from. The only thing I can think of is there is an issue with the urls reference, but am too new to know for sure?

(11_env) C:\Users\kevin\Documents\webapps>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\kevin\AppData\Local\Programs\Python\Python37-32\lib\threading.py", line 917, in _bootstrap_inner
    self.run()
  File "C:\Users\kevin\AppData\Local\Programs\Python\Python37-32\lib\threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\kevin\Documents\webapps\11_env\lib\site-packages\django\utils\autoreload.py", line 54, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\kevin\Documents\webapps\11_env\lib\site-packages\django\core\management\commands\runserver.py", line 117, in inner_run
    self.check(display_num_errors=True)
  File "C:\Users\kevin\Documents\webapps\11_env\lib\site-packages\django\core\management\base.py", line 390, in check
    include_deployment_checks=include_deployment_checks,
  File "C:\Users\kevin\Documents\webapps\11_env\lib\site-packages\django\core\management\base.py", line 377, in _run_checks
    return checks.run_checks(**kwargs)
  File "C:\Users\kevin\Documents\webapps\11_env\lib\site-packages\django\core\checks\registry.py", line 72, in run_checks
    new_errors = check(app_configs=app_configs)
  File "C:\Users\kevin\Documents\webapps\11_env\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
    return check_resolver(resolver)
  File "C:\Users\kevin\Documents\webapps\11_env\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
    return check_method()
  File "C:\Users\kevin\Documents\webapps\11_env\lib\site-packages\django\urls\resolvers.py", line 398, in check
    for pattern in self.url_patterns:
  File "C:\Users\kevin\Documents\webapps\11_env\lib\site-packages\django\utils\functional.py", line 80, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\kevin\Documents\webapps\11_env\lib\site-packages\django\urls\resolvers.py", line 579, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "C:\Users\kevin\Documents\webapps\11_env\lib\site-packages\django\utils\functional.py", line 80, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\kevin\Documents\webapps\11_env\lib\site-packages\django\urls\resolvers.py", line 572, in urlconf_module
    return import_module(self.urlconf_name)
  File "C:\Users\kevin\AppData\Local\Programs\Python\Python37-32\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\kevin\Documents\webapps\learning_log\urls.py", line 21, in <module>
    path('users/', include('users.urls')),
  File "C:\Users\kevin\Documents\webapps\11_env\lib\site-packages\django\urls\conf.py", line 34, in include
    urlconf_module = import_module(urlconf_module)
  File "C:\Users\kevin\AppData\Local\Programs\Python\Python37-32\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'users.urls'

Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\kevin\Documents\webapps\11_env\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "C:\Users\kevin\Documents\webapps\11_env\lib\site-packages\django\core\management\__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\kevin\Documents\webapps\11_env\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\kevin\Documents\webapps\11_env\lib\site-packages\django\core\management\commands\runserver.py", line 60, in execute
    super().execute(*args, **options)
  File "C:\Users\kevin\Documents\webapps\11_env\lib\site-packages\django\core\management\base.py", line 364, in execute
    output = self.handle(*args, **options)
  File "C:\Users\kevin\Documents\webapps\11_env\lib\site-packages\django\core\management\commands\runserver.py", line 95, in handle
    self.run(**options)
  File "C:\Users\kevin\Documents\webapps\11_env\lib\site-packages\django\core\management\commands\runserver.py", line 102, in run
    autoreload.run_with_reloader(self.inner_run, **options)
  File "C:\Users\kevin\Documents\webapps\11_env\lib\site-packages\django\utils\autoreload.py", line 577, in run_with_reloader
    start_django(reloader, main_func, *args, **kwargs)
  File "C:\Users\kevin\Documents\webapps\11_env\lib\site-packages\django\utils\autoreload.py", line 562, in start_django
    reloader.run(django_main_thread)
  File "C:\Users\kevin\Documents\webapps\11_env\lib\site-packages\django\utils\autoreload.py", line 280, in run
    self.run_loop()
  File "C:\Users\kevin\Documents\webapps\11_env\lib\site-packages\django\utils\autoreload.py", line 286, in run_loop
    next(ticker)
  File "C:\Users\kevin\Documents\webapps\11_env\lib\site-packages\django\utils\autoreload.py", line 326, in tick
    for filepath, mtime in self.snapshot_files():
  File "C:\Users\kevin\Documents\webapps\11_env\lib\site-packages\django\utils\autoreload.py", line 342, in snapshot_files
    for file in self.watched_files():
  File "C:\Users\kevin\Documents\webapps\11_env\lib\site-packages\django\utils\autoreload.py", line 241, in watched_files
    yield from iter_all_python_module_files()
  File "C:\Users\kevin\Documents\webapps\11_env\lib\site-packages\django\utils\autoreload.py", line 103, in iter_all_python_module_files
    return iter_modules_and_files(modules, frozenset(_error_files))
  File "C:\Users\kevin\Documents\webapps\11_env\lib\site-packages\django\utils\autoreload.py", line 128, in iter_modules_and_files
    if not path.exists():
  File "C:\Users\kevin\AppData\Local\Programs\Python\Python37-32\lib\pathlib.py", line 1339, in exists
    self.stat()
  File "C:\Users\kevin\AppData\Local\Programs\Python\Python37-32\lib\pathlib.py", line 1161, in stat
    return self._accessor.stat(self)
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: '<frozen importlib._bootstrap>'

(11_env) C:\Users\kevin\Documents\webapps>OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: '<frozen importlib._bootstrap>'

HERE IS MY VIEWS.PY


from django.shortcuts import render
from django.http import HttpResponseRedirect
from django.urls import reverse

from .models import Topic, Entry
from .forms import TopicForm, EntryForm

# Create your views here.

def index(request):
	"""The home page for learning log"""
	return render(request, 'learning_logs/index.html')

def topics(request):
	"""Show all topics."""
	topics = Topic.objects.order_by('date_added')
	context = {'topics': topics}
	return render(request, 'learning_logs/topics.html', context)

def topic(request, topic_id):
	"""Show a single topic and all its entries."""
	topic = Topic.objects.get(id=topic_id)
	entries = topic.entry_set.order_by('-date_added')
	context = {'topic': topic, 'entries': entries}
	return render(request, 'learning_logs/topic.html', context)

def new_topic(request):
	"""Add a new topic."""
	if request.method != 'POST':
		#No data submitted; create a blank form.
		form = TopicForm()
	else:
		#POST data submitted; process data.
		form = TopicForm(data=request.POST)
		if form.is_valid():
			form.save()
			return HttpResponseRedirect(reverse('learning_logs:topics'))
			
	context = {'form': form}
	return render(request, 'learning_logs/new_topic.html', context)

def new_entry(request, topic_id):
	"""Add a new entry."""
	topic = Topic.objects.get(id=topic_id)
	
	if request.method != 'POST':
		#No data submitted; create blank form.
		form = EntryForm()
	else:
		#Post data submitted; process data.
		form = EntryForm(data=request.POST)
		if form.is_valid():
			new_entry = form.save(commit=False)
			new_entry.topic = topic
			new_entry.save()
			return HttpResponseRedirect(reverse('learning_logs:topic', args=[topic_id]))
										
	context = {'topic': topic, 'form': form}
	return render(request, 'learning_logs/new_entry.html', context)
	
def edit_entry(request, entry_id):
	"""Edit an existing entry."""
	entry = Entry.objects.get(id=entry_id)
	topic = entry.topic
	
	if request.method != 'POST':
		# Initial request; pre-fill form with the current entry..
		form = EntryForm(instance=entry)
	else:
		# POST data submitted; process data.
		form = EntryForm(instance=entry, data=request.POST)
		if form.is_valid():
			form.save()
			return HttpResponseRedirect(reverse('learning_logs:topic', args=[topic.id]))
			
	context = {'entry': entry, 'topic': topic, 'form': form}
	return render(request, 'learning_logs/edit_entry.html', context)
HERE IS MY URLS.PY FILE IN THE LEARNING_LOG\USERS DIRECTORY:

"""Defines url patterns for users."""

from django.urls import path
from django.contrib.auth import views as auth_views

from . import views

app_name = 'users'
urlpatterns = [
	# Login page.
    path('login/',
    	auth_views.LoginView.as_view(template_name='users/login.html'),
    	name='login'),
]
HERE IS MY BASE.PY:
<p>
  <a href="{% url 'learning_logs:index' %}">Learning Log</a> - 
  <a href="{% url 'learning_logs:topics' %}">Topics</a> -
  {% if user.is_authenticated %}
    Hello, {{ user.username }}.
  {% else %}
    <a href="{% url 'users:login' %}">log in</a>
  {% endif %}  
</p>
{% block content %}{% endblock content %}

Here is my urls.py located in the root folder:
"""learning_log URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/2.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.urls import path, include
from django.contrib import admin

urlpatterns = [
    path('admin/', admin.site.urls),
    path('users/', include('users.urls')),
    path('', include('learning_logs.urls')),
]
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020