Thanks for the welcome Ken!
Answers to your questions:
- Did you stop and then restart the server? Yes
- If you stop the server and try to go to that page, what happens? Yes. Same thing happened.
- Did you verify that you have saved all the changes made? Yes
Post the contents of both of your urls.py files (both the one in your mysite directory and the one in your polls directory).
Side note, please do not post images of code. Copy / paste the contents of the files into the body of your post, marked as “preformatted text”.
“”"
Here are the contents of my settings file:
Django settings for DjangoProject project.
Generated by 'django-admin startproject' using Django 5.2.
For more information on this file, see
https://docs.djangoproject.com/en/5.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.2/ref/settings/
"""
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-!7f(@xls3_v7c3$en-qn2hp#w4$7(kjt4%&x8+oy!@@jit8=+n'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'polls.apps.PollsConfig'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'DjangoProject.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR / 'templates']
,
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'DjangoProject.wsgi.application'
# Database
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/5.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.2/howto/static-files/
STATIC_URL = 'static/'
# Default primary key field type
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
Contents of urls.py file from mysite directory:
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path("polls/", include("polls.urls")),
path("admin/", admin.site.urls),
]
Contents of urls.py in polls directory:
from django.urls import path
from . import views
urlpatterns = [
path("", views.index, name="index"),
]
I’m doing this in PyCharm. To be sure I am following the tutorial exactly, I deleted the Django project completely and recreated. I think I failed to edit both urls.py the first time.
Running the server from Windows Powershell now produces this error:
PS C:\Users\markb\PycharmProjects\DjangoProject> py 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\markb\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\apps\registry.py", line 158, in get_app_config
return self.app_configs[app_label]
~~~~~~~~~~~~~~~~^^^^^^^^^^^
KeyError: 'admin'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\markb\AppData\Local\Programs\Python\Python313\Lib\threading.py", line 1041, in _bootstrap_inner
self.run()
~~~~~~~~^^
File "C:\Users\markb\AppData\Local\Programs\Python\Python313\Lib\threading.py", line 992, in run
self._target(*self._args, **self._kwargs)
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\markb\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
~~^^^^^^^^^^^^^^^^^
File "C:\Users\markb\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\core\management\commands\runserver.py", line 134, in inner_run
self.check(**check_kwargs)
~~~~~~~~~~^^^^^^^^^^^^^^^^
File "C:\Users\markb\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\core\management\base.py", line 492, in check
all_issues = checks.run_checks(
app_configs=app_configs,
...<2 lines>...
databases=databases,
)
File "C:\Users\markb\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\core\checks\registry.py", line 89, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "C:\Users\markb\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\core\checks\urls.py", line 136, in check_custom_error_handlers
handler = resolver.resolve_error_handler(status_code)
File "C:\Users\markb\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\urls\resolvers.py", line 732, in resolve_error_handler
callback = getattr(self.urlconf_module, "handler%s" % view_type, None)
^^^^^^^^^^^^^^^^^^^
File "C:\Users\markb\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\utils\functional.py", line 47, in __get__
res = instance.__dict__[self.name] = self.func(instance)
~~~~~~~~~^^^^^^^^^^
File "C:\Users\markb\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\urls\resolvers.py", line 711, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\markb\AppData\Local\Programs\Python\Python313\Lib\importlib\__init__.py", line 88, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 1026, in exec_module
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "C:\Users\markb\PycharmProjects\DjangoProject\DjangoProject\urls.py", line 23, in <module>
path("admin/", admin.site.urls),
^^^^^^^^^^^^^^^
File "C:\Users\markb\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\utils\functional.py", line 251, in inner
self._setup()
~~~~~~~~~~~^^
File "C:\Users\markb\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\contrib\admin\sites.py", line 610, in _setup
AdminSiteClass = import_string(apps.get_app_config("admin").default_site)
~~~~~~~~~~~~~~~~~~~^^^^^^^^^
File "C:\Users\markb\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\apps\registry.py", line 165, in get_app_config
raise LookupError(message)
LookupError: No installed app with label 'admin'.