Я пытаюсь загрузить шаблон, но, похоже, он продолжает искать шаблон по пути, который не существует.Я ищу, чтобы загрузить visit_form.html
, но он продолжает искать в clincher/visit_form
и не может избавиться от "clincher/
" части расположения шаблона.Ранее он был настроен таким образом, но изменил его, когда я переместил расположение шаблонов в соответствующее приложение.
URL-адрес шаблона: <td><a href="{% url 'clincher:visit_form' main.id %}" role="button" class="btn btn-primary btn-xs">New Consult</a></td>
Main / Urls.py:
from django.contrib import admin
from django.urls import include, path
from django.views.generic import RedirectView
from clincher import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.index, name='index'),
path('clincher/', include('clincher.urls'), name='clincher'),
path('accounts/', include('accounts.urls')),
path('accounts/', include('django.contrib.auth.urls')),
path('', RedirectView.as_view(url='clincher/templates/')),
]
Clincher / Urls.py
from django.conf.urls import url
from . import views
from django.urls import path
app_name = 'clincher'
urlpatterns = [
path('', views.index, name='index'),
path('main/', views.MainListView.as_view(), name='main'),
path('main/<int:pk>', views.MainDetailView.as_view(), name='main_detail'),
path('visit/add/<int:pk>', views.VisitCreate.as_view(), name='visit_form'),
]
Views.py
class VisitCreate( CreateView):
login_url = '/login/'
redirect_field_name = 'index'
model = Visit
fields = [ 'visit_label', 'visit_type', 'visit_progress_notes']
template = 'templates/visit_form.html'
def form_valid(self, form):
form.instance.fk_visit_user = self.request.user
form.instance.fk_visit_main = Main.object.get(self.kwargs['pk'])
return super(VisitCreate, self).form_valid(form)
def get_success_url(self):
return reverse('main_detail', args={'pk': self.object.id})
Settings.py
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'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 = [
'clincher.apps.clincherConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'accounts',
]
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
И, наконец, мой Traceback:
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/clincher/visit/add/2
Django Version: 2.0.4
Python Version: 3.6.4
Installed Applications:
['clincher.apps.clincherConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'accounts']
Installed 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']
Django tried loading these templates, in this order:
Using engine django:
django.template.loaders.filesystem.Loader: /Users/nrsmoll/PycharmProjects/clincher/templates/clincher/visit_form.html (Source does not exist)
django.template.loaders.app_directories.Loader: /Users/nrsmoll/PycharmProjects/clincher/clincher/templates/clincher/visit_form.html (Source does not exist)
django.template.loaders.app_directories.Loader: /Users/nrsmoll/venv/lib/python3.6/site-packages/django/contrib/admin/templates/clincher/visit_form.html (Source does not exist)
django.template.loaders.app_directories.Loader: /Users/nrsmoll/venv/lib/python3.6/site-packages/django/contrib/auth/templates/clincher/visit_form.html (Source does not exist)
django.template.loaders.app_directories.Loader: /Users/nrsmoll/PycharmProjects/clincher/accounts/templates/clincher/visit_form.html (Source does not exist)
Traceback:
File "/Users/nrsmoll/venv/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
35. response = get_response(request)
File "/Users/nrsmoll/venv/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
158. response = self.process_exception_by_middleware(e, request)
File "/Users/nrsmoll/venv/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
156. response = response.render()
File "/Users/nrsmoll/venv/lib/python3.6/site-packages/django/template/response.py" in render
106. self.content = self.rendered_content
File "/Users/nrsmoll/venv/lib/python3.6/site-packages/django/template/response.py" in rendered_content
81. template = self.resolve_template(self.template_name)
File "/Users/nrsmoll/venv/lib/python3.6/site-packages/django/template/response.py" in resolve_template
63. return select_template(template, using=self.using)
File "/Users/nrsmoll/venv/lib/python3.6/site-packages/django/template/loader.py" in select_template
47. raise TemplateDoesNotExist(', '.join(template_name_list), chain=chain)
Exception Type: TemplateDoesNotExist at /clincher/visit/add/2
Exception Value: clincher/visit_form.html
Все, что мне нужно, это избавиться от части "клинчера""clincher / visit_form.html".