2017-02-10 1 views
0

다음 장고 자습서 (https://docs.djangoproject.com/en/1.10/intro/reusable-apps/)를 따랐습니다. oldcity이라는 프로젝트와 oldantwerp이라는 앱이 있습니다. 앱은 상위 디렉토리 인 django-oldantwerp에 있고 앱 디렉토리 자체는 서브 디렉토리 templates을 가지고 있습니다. 내 프로젝트가 찾고있는 index.html 파일과 같이 위치하고 있습니다 :Django 패키지를 사용할 때 TemplateDoesNotExist

INSTALLED_APPS = [ 
'django.contrib.admin', 
'django.contrib.auth', 
'django.contrib.contenttypes', 
'django.contrib.sessions', 
'django.contrib.messages', 
'django.contrib.staticfiles', 
'oldantwerp' 
] 

와 urls.py에서 :

django-oldantwerp>oldantwerp>templates>oldantwerp>index.html 

내가 settings.py에서를 포함하여 내 프로젝트에이 응용 프로그램을 사용하려 합니다 (projec에서), 그래서 같은 :

urlpatterns = [ 
url(r'^oldantwerp/', include('oldantwerp.urls')), 
url(r'^admin/', admin.site.urls), 
] 

내가 관리자 페이지로 이동, 모든 작품,하지만 인덱스 페이지를 열려고 할 때이 오류가 발생합니다 :

Template loader postmortem 
Django tried loading these templates, in this order: 

Using engine django: 
* django.template.loaders.filesystem.Loader: /Users/Vincent/Apps/oldcity/templates/oldantwerp/index.html (Source does not exist) 
* django.template.loaders.app_directories.Loader: /Users/Vincent/Apps/oldcity/venv/lib/python3.4/site-packages/django/contrib/admin/templates/oldantwerp/index.html (Source does not exist) 
* django.template.loaders.app_directories.Loader: /Users/Vincent/Apps/oldcity/venv/lib/python3.4/site-packages/django/contrib/auth/templates/oldantwerp/index.html (Source does not exist) 

그리고 그것은 또한 다른 파일을 검색하려고 : 나는 그런 생각하지 않기 때문에 place_list.html, 이상하다

TemplateDoesNotExist at /oldantwerp/ 

그것은과 같이 index.html 파일을 찾기 위해 노력 말한다 파일.

무엇이 잘못 될 수 있습니까?

이것은 oldantwerp 폴더에 views.py의 코드

편집 : 난 그냥했을 때 모든 일을했다 :

class IndexView(generic.ListView): 
    template_name = 'oldantwerp/index.html' 
    context_object_name = 'places' 

    def get_queryset(self): 
     return Place.objects.order_by('id')[:] 

EDIT 언급

어쩌면 가치 oldicty 프로젝트 폴더에 하위 폴더로 oldantwerp 폴더가 있습니다. 이 오류는 외부 패키지에서 구현 한 후에 만 ​​발생합니다.

편집이 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', 
     ], 
    }, 
}, 
] 
+1

우리에게주지하시기 바랍니다 귀하의 의견 ... –

+0

내가 거기에 편집을 TEMPLATE_NAME합니다. – Vincent

+0

[튜토리얼] (https://docs.djangoproject.com/en/1.10/intro/reusable-apps/)의 매니페스트 파일 (6 단계)에 템플릿을 포함 시켰습니까? 'import oldantwerp;를 입력하면, print (oldantwerp .__ file __)'를 코드에 추가하면 어떤 경로로 표시됩니까? – Alasdair

답변

0

한 가능성이 가장 높은 문제는 당신이보기에 잘못된 템플릿 이름을 가지고있을 수 있습니다. index.html이 아닌보기에서 oldantwerp/index.html 템플릿을 사용해야합니다. 그래서 당신이를 만들 수 있습니다

django-oldantwerp>oldantwerp>templates>oldantwerp>index.html. 

: 나는 당신의 첫 번째 문이 제대로 디렉토리 구조가 읽으면 * django.template.loaders.filesystem.Loader: /Users/Vincent/Apps/oldcity/templates/oldantwerp/index.html (Source does not exist). : 당신이 당신의 스택 트레이스를 보면

+0

질문을 편집했고 실제로 oldantwerp/index.html을 사용했습니다. – Vincent

0

당신은 응용 프로그램에서 템플릿을로드하려고 것을 볼 수 있습니다 디렉토리 구조를 사용하여 django가 템플릿 디렉토리를 식별 할 수있게하거나 설정 파일에서 템플릿 상수를 업데이트하고 django가 템플릿을 찾을 수있는 실제 위치를 지정할 수 있습니다.

+0

두 경로의 차이점은 첫 번째가 색인을 찾으려한다는 것입니다. html in oldcity (project) 폴더에 있지만 실제 템플릿 폴더는 django-oldantwerp 패키지에 있습니다. 프로젝트 폴더 자체에있는 응용 프로그램 용 템플릿을 저장하는 것은 좋지 않다고 생각합니다. – Vincent

0

settings.py에서 DIRS를 다음과 같이 설정할 수 있습니다 : os.path.join (BASE_DIR, 'templates'), 템플릿 폴더에서 oldantwerp 폴더를 삭제하고 템플릿에 index.html을 추가하십시오. 그 후

, 편집 TEMPLATE_NAME = 'oldantwerp/index.html을'= 'index.html을'

+0

시도해 보았습니다. 하지만 작동하지 않습니다 .. – Vincent

+0

은 APP_DIRS가 True로 설정되어 있습니까? –

+0

한 가지 더 할 수 있습니다, Pycharm을 사용합니까? –

관련 문제