Всем привет. Никак не получается подключить и запустить index.html на уровне проекта. Обшарил разные форумы. Ничего не помогает. Прошу помочь понять в чем я не прав и как это исправить.
Request Method: GET
Request URL: http://localhost:8000/
Django Version: 2.0.7
Python Version: 3.6.5
Exception Type: TemplateDoesNotExist
Exception Value: index.html
Internal Server Error:
Traceback :
File "C:\Users\Dan\Desktop\myvirtualenv\firstproject\lib\site-packages\django\core\handlers\exception.py", line 35, in inner
response = get_response(request)
File "C:\Users\Dan\Desktop\myvirtualenv\firstproject\lib\site-packages\django\core\handlers\base.py", line 128, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\Dan\Desktop\myvirtualenv\firstproject\lib\site-packages\django\core\handlers\base.py", line 126, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\Dan\Desktop\firstproject\teststaticapp\views.py", line 5, in new_home
return render(request, 'index.html')
File "C:\Users\Dan\Desktop\myvirtualenv\firstproject\lib\site-packages\django\shortcuts.py", line 36, in render
content = loader.render_to_string(template_name, context, request, using=using)
File "C:\Users\Dan\Desktop\myvirtualenv\firstproject\lib\site-packages\django\template\loader.py", line 61, in render_to_string
template = get_template(template_name, using=using)
File "C:\Users\Dan\Desktop\myvirtualenv\firstproject\lib\site-packages\django\template\loader.py", line 19, in get_template
raise TemplateDoesNotExist(template_name, chain=chain)
django.template.exceptions.TemplateDoesNotExist: index.html
settings.py
TEMPLATE_DIR = os.path.join(BASE_DIR, 'templates')
STATICFILE_DIR = os.path.join(BASE_DIR, 'static')
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [TEMPLATE_DIR,],
'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',
],
},
},
]
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'firstapp',
'testurlapp',
'teststaticapp',
]
STATICFILES_DIRS = [
STATICFILE_DIR,
]
views.py
from django.shortcuts import render
def new_home(request):
return render(request, 'index.html')
urls.py
from django.contrib import admin
from django.urls import path, include
from teststaticapp import views
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.new_home, name='index'),
#path('testapp/', include('testurlapp.test_urls'))
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Updated 16 July 2018, 12:45 by averkindany.