Ошибка при использовании django_hosts
Начал использовать django_hosts для сабдоменов, но столкнулся с ошибкой:
Traceback (most recent call last):
File "C:\Users\Tim\AppData\Local\Programs\Python\Python310\lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "C:\Users\Tim\AppData\Local\Programs\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 80, in __call__
return self.application(environ, start_response)
File "C:\Users\Tim\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\handlers\wsgi.py", line 124, in __call__
response = self.get_response(request)
File "C:\Users\Tim\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\handlers\base.py", line 140, in get_response
response = self._middleware_chain(request)
File "C:\Users\Tim\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\handlers\exception.py", line 57, in inner
response = response_for_exception(request, exc)
File "C:\Users\Tim\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\handlers\exception.py", line 140, in response_for_exception
response = handle_uncaught_exception(
File "C:\Users\Tim\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\handlers\exception.py", line 181, in handle_uncaught_exception
return debug.technical_500_response(request, *exc_info)
File "C:\Users\Tim\AppData\Local\Programs\Python\Python310\lib\site-packages\django\views\debug.py", line 69, in technical_500_response
html = reporter.get_traceback_html()
File "C:\Users\Tim\AppData\Local\Programs\Python\Python310\lib\site-packages\django\views\debug.py", line 428, in get_traceback_html
c = Context(self.get_traceback_data(), use_l10n=False)
File "C:\Users\Tim\AppData\Local\Programs\Python\Python310\lib\site-packages\django\views\debug.py", line 411, in get_traceback_data
c["raising_view_name"] = get_caller(self.request)
File "C:\Users\Tim\AppData\Local\Programs\Python\Python310\lib\site-packages\django\views\debug.py", line 102, in get_caller
resolver_match = resolve(request.path)
File "C:\Users\Tim\AppData\Local\Programs\Python\Python310\lib\site-packages\django\urls\base.py", line 24, in resolve
return get_resolver(urlconf).resolve(path)
File "C:\Users\Tim\AppData\Local\Programs\Python\Python310\lib\site-packages\django\urls\resolvers.py", line 683, in resolve
for pattern in self.url_patterns:
File "C:\Users\Tim\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\functional.py", line 47, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\Tim\AppData\Local\Programs\Python\Python310\lib\site-packages\django\urls\resolvers.py", line 735, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\Tim\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\functional.py", line 47, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\Tim\AppData\Local\Programs\Python\Python310\lib\site-packages\django\urls\resolvers.py", line 728, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\Tim\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'path.to'
[15/Apr/2024 18:59:28] "GET /favicon.ico HTTP/1.1" 500 59
файл settings.py
import os
from pathlib import Path
from django.urls import re_path
from django.views.static import serve
from django.conf import settings
# 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.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'some_key'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['host.ru', 'localhost', "www.localhost"]
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'main',
'apps',
'django.contrib.sites',
'django.contrib.sitemaps',
'django_hosts',
]
MIDDLEWARE = [
'django_hosts.middleware.HostsRequestMiddleware',
'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',
'django_hosts.middleware.HostsResponseMiddleware',
]
ROOT_URLCONF = 'TimAnt32.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'TimAnt32.wsgi.application'
# Database
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/5.0/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',
},
]
AUTHENTICATION_BACKENDS = (
('django.contrib.auth.backends.ModelBackend'),
)
CSRF_TRUSTED_ORIGINS = ['https://*.timant32.ru','https://*.127.0.0.1']
# Internationalization
# https://docs.djangoproject.com/en/5.0/topics/i18n/
LANGUAGE_CODE = 'ru'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.0/howto/static-files/
STATIC_URL = 'main/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
SITE_ID= 1
# Default primary key field type
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
# urlpatterns = [
# # your other paths here
# re_path(r'^media/(?P<path>.*)$', serve,{'document_root': settings.MEDIA_ROOT}),
# re_path(r'^static/(?P<path>.*)$', serve,{'document_root': settings.STATIC_ROOT}),
# ]
ROOT_HOSTCONF = 'TimAnt32.hosts'
DEFAULT_HOST = 'www'
файл hosts.py
from django_hosts import patterns, host
from django.conf import settings
host_patterns = patterns('path.to',
host(r'www', settings.ROOT_URLCONF, name='www'),
)
помогите пожалуйста с решением этой проблемы