2014-04-07 46 views
5

Hej! Molti thread qui avevano la stessa didascalia, ma nessuno di loro ha risolto il mio problema. Ho un sito Django che può accedere/admin (ma sembra brutto). Ma su/appare la seguente pagina di errore (DEBUG = True in settings.py):TemplateDoesNotExist at/

TemplateDoesNotExist at/

index.html 

Request Method:  GET 
Request URL: http://iecl.uni-potsdam.de/ 
Django Version:  1.4.5 
Exception Type:  TemplateDoesNotExist 
Exception Value:  

index.html 

Exception Location:  /usr/lib/python2.7/dist-packages/django/template/loader.py in find_template, line 138 
Python Executable: /usr/bin/python 
Python Version:  2.7.3 
Python Path:  

['/home/python/iecl/lib/python2.7/site-packages/distribute-0.6.28-py2.7.egg', 
'/home/python/iecl/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg', 
'/usr/lib/python2.7', 
'/usr/lib/python2.7/plat-linux2', 
'/usr/lib/python2.7/lib-tk', 
'/usr/lib/python2.7/lib-old', 
'/usr/lib/python2.7/lib-dynload', 
'/usr/local/lib/python2.7/dist-packages', 
'/usr/lib/python2.7/dist-packages', 
'/usr/lib/pymodules/python2.7', 
'/home/python/iecl/lib/python2.7/site-packages', 
'/home/django/django'] 

Server time: Mon, 7 Apr 2014 11:28:46 +0200 
Template-loader postmortem 

Django tried loading these templates, in this order: 

    Using loader django.template.loaders.filesystem.Loader: 
     /home/django/django/templates/iecl_dev/index.html (File does not exist) 
    Using loader django.template.loaders.app_directories.Loader: 
     /usr/lib/python2.7/dist-packages/django/contrib/auth/templates/index.html (File does not exist) 
     /usr/lib/python2.7/dist-packages/django/contrib/admin/templates/index.html (File does not exist) 

In realtà, il file /home/django/django/templates/iecl_dev/index.html esiste e ho anche provato senza successo chmod o+r index.html .

L'uscita del python iecl_dev/manage.py runserver 0.0.0.0:0 è

Validating models... 

0 errors found 
Django version 1.4.5, using settings 'iecl_dev.settings' 
Development server is running at http://0.0.0.0:0/ 
Quit the server with CONTROL-C. 

quindi tutto sembra bene qui.

Ciò che mi lascia perplesso: I file * .pyc vengono creati automaticamente quando vengono eseguiti i file * .py, giusto? Dopo python iecl_dev/manage.py runserver 0.0.0.0:0 è stato creato un file /home/django/django/iecl_dev/settings.pyc. Ma non viene creato, quando carico la pagina nel mio browser web. Significa che il settings.py non viene mai caricato? E come può dire Django, un file, che esiste, non esisterebbe?

Edit¹:
mio settings.py appare come segue:

import django.conf.global_settings as DEFAULT_SETTINGS 
import os 
DEBUG = True 
TEMPLATE_DEBUG = DEBUG 

ADMINS = (
) 

SETTINGS_PATH = os.path.realpath(os.path.dirname(__file__)) 

MANAGERS = ADMINS 
DATABASES = {                                       $ 
    'default': {                                      $ 
     'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. 
     'NAME': 'iecl',      # Or path to database file if using sqlite3. 
       'USER': 'iecl',      # Not used with sqlite3. 
     'PASSWORD': '<xxx>',     # Not used with sqlite3. 
     'HOST': '',      # Set to empty string for localhost. Not used with sqlite3.                 $ 
     'PORT': '',      # Set to empty string for default. Not used with sqlite3. 
    } 
} 
TIME_ZONE = 'Europe/Berlin' 

LANGUAGE_CODE = 'en-us' 

SITE_ID = 1 

USE_I18N = True 

MEDIA_ROOT = '/var/www/django_media/iecl_dev/media/' 
MEDIA_URL = '' 

ADMIN_MEDIA_PREFIX = '/media/admin_media/' 

SECRET_KEY = '<xxx>' 

TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader', 
    'django.template.loaders.app_directories.Loader', 
) 

MIDDLEWARE_CLASSES = (
     'django.middleware.csrf.CsrfViewMiddleware', 
     'django.middleware.common.CommonMiddleware', 
    'django.contrib.sessions.middleware.SessionMiddleware', 
    'django.contrib.auth.middleware.AuthenticationMiddleware', 
     'django.contrib.messages.middleware.MessageMiddleware', 
) 

ROOT_URLCONF = 'iecl_dev.urls' 

TEMPLATE_DIRS = (
     os.path.join(SETTINGS_PATH, 'templates'), 
) 
INSTALLED_APPS = (
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.sites', 
     'iecl_dev.showStudents', 
     'django.contrib.admin', 
) 

TEMPLATE_CONTEXT_PROCESSORS = DEFAULT_SETTINGS.TEMPLATE_CONTEXT_PROCESSORS + (
) 

Edit²:

The contents of `/home/django/django/` are as follows: 

/home/django/django/: 
iecl2 
iecl_dev 
templates 

/home/django/django/iecl2: 
__init__.py 
__init__.pyc 
manage.py 
settings.py 
settings.pyc 
showStudents 
urls.py 
urls.pyc 

/home/django/django/iecl2/showStudents: 
__init__.py 
__init__.pyc 
admin.py 
context_processors.py 
models.py 
models.pyc 
views.py 
views.pyc 

/home/django/django/iecl_dev: 
__init__.py 
__init__.pyc 
manage.py 
piwik 
settings.py 
settings.pyc 
showStudents 
urls.py 
urls.pyc 

/home/django/django/iecl_dev/piwik: 
__init__.py 
app_settings.py 
context_processors.py 
models.py 
tests.py 
urls.py 
views.py 

/home/django/django/iecl_dev/showStudents: 
__init__.py 
__init__.pyc 
admin.py 
context_processors.py 
models.py 
models.pyc 
views.py 

/home/django/django/templates: 
iecl 
iecl_dev 
/home/django/django/templates/iecl: 
500.html 
admin 
changePW.html 
editStudent.html 
feedback.html 
feedback_thanks.html 
index.html 
location.html 
login.html 
page.html 
password_changed.html 
showStudent.html 
studentsOverview.html 

/home/django/django/templates/iecl/admin: 
404.html 
500.html 
actions.html 
app_index.html 
auth 
base.html 
base_site.html 
change_form.html 
change_list.html 
change_list_results.html 
date_hierarchy.html 
delete_confirmation.html 
delete_selected_confirmation.html 
edit_inline 
filter.html 
includes 
index.html 
invalid_setup.html 
login.html 
object_history.html 
pagination.html 
prepopulated_fields_js.html 
search_form.html 
showStudents 
submit_line.html 

/home/django/django/templates/iecl/admin/auth: 
user 

/home/django/django/templates/iecl/admin/auth/user: 
add_form.html 
change_password.html 

/home/django/django/templates/iecl/admin/edit_inline: 
stacked.html 
tabular.html 

/home/django/django/templates/iecl/admin/includes: 
fieldset.html 

/home/django/django/templates/iecl/admin/showStudents: 
pagecontent 
userpagecontent 

/home/django/django/templates/iecl/admin/showStudents/pagecontent: 
change_form.html 

/home/django/django/templates/iecl/admin/showStudents/userpagecontent: 
change_form.html 

/home/django/django/templates/iecl_dev: 
500.html 
__init__.py 
admin 
changePW.html 
editStudent.html 
feedback.html 
feedback_thanks.html 
index.html 
location.html 
login.html 
page.html 
password_changed.html 
piwik 
showStudent.html 
studentsOverview.html 

/home/django/django/templates/iecl_dev/admin: 
404.html 
500.html 
actions.html 
app_index.html 
auth 
base.html 
base_site.html 
change_form.html 
change_list.html 
change_list_results.html 
date_hierarchy.html 
delete_confirmation.html 
delete_selected_confirmation.html 
edit_inline 
filter.html 
includes 
index.html 
invalid_setup.html 
login.html 
object_history.html 
pagination.html 
prepopulated_fields_js.html 
search_form.html 
showStudents 
submit_line.html 

/home/django/django/templates/iecl_dev/admin/auth: 
user 

/home/django/django/templates/iecl_dev/admin/auth/user: 
add_form.html 
change_password.html 

/home/django/django/templates/iecl_dev/admin/edit_inline: 
stacked.html 
tabular.html 

/home/django/django/templates/iecl_dev/admin/includes: 
fieldset.html 

/home/django/django/templates/iecl_dev/admin/showStudents: 
pagecontent 
userpagecontent 

/home/django/django/templates/iecl_dev/admin/showStudents/pagecontent: 
change_form.html 

/home/django/django/templates/iecl_dev/admin/showStudents/userpagecontent: 
change_form.html 

/home/django/django/templates/iecl_dev/piwik: 
tracking.html 

Edit³:
Ok. Questo è risolto per me ora. La soluzione era un conglomerato di cose diverse. Uno dei problemi era i diritti mancanti. L'utente che esegue Django non può elencare il contenuto della cartella templates /. chmod o+x templates/ ha fatto il lavoro. Poi c'erano alcune impostazioni in settings.py, che cambiava il posto in cui cercare i modelli da templates/iecl_dev/a iecl_dev/templates /. Ho visto questo percorso errato nel messaggio di errore nel mio browser web. Ma semplicemente riportando il settings.py alla vecchia versione, non era abbastanza. Alcuni servizi necessari per essere riavviati. Ho semplicemente riavviato la macchina e tutto andava bene. Miracolosamente, anche la pagina/admin/ora è bella.

Mille grazie per tutti i vostri suggerimenti.

+1

E dove si sta cercando di rendere il vostro modello. –

+0

Vedere la mia risposta qui se non è ancora stato risolto, http://stackoverflow.com/a/32358905/303681 – mmrs151

risposta

12

Da quello che hai mostrato, penso che potresti avere un problema con il layout del tuo progetto.

Di solito, si è impostato come segue:

├── manage.py 
├── yourproject 
│   ├── __init__.py 
│   ├── settings.py 
│   ├── templates 
│   ├── urls.py 
│   ├── wsgi.py 
│   └── wsgi.pyc 
├── yourfirstapp 
│   ├── __init__.py 
│   ├── admin.py 
│   ├── models.py 
│   ├── templates 
│   ├── tests.py 
│   ├── urls.py 
│   └── views.py 
├── yoursecondapp 
    ├── __init__.py 
    ├── admin.py 
    ├── models.py 
    ├── templates 
    ├── tests.py 
    ├── urls.py 
    └── views.py 

Come si può vedere, ogni app all'interno del vostro progetto può avere un proprio elenco templates. yourproject è un po 'particolare, perché memorizza anche file unici, come settings.py e wsgi.py. Tuttavia, puoi considerarlo e usarlo come un'app.

Ora, se si desidera utilizzare un modello memorizzato in yourproject/templates, sarà necessario aggiungere yourproject alle impostazioni INSTALLED_APPS.

Aiuta? In caso contrario, puoi modificare il tuo post originale con il layout del tuo progetto?

+0

Ok. Sembra interessante. Ma il mio layout differisce completamente da quello (vedi sopra). Non sono l'autore di questo sito e non posso spiegarne il motivo. Quindi, quando il mio manage.py e il mio settings.py sono in., I modelli sono in ../templates/iecl_dev/. Cosa dovrei aggiungere a INSTALLED_APPS? – user3506025

+0

Dato che il layout è molto diverso da quello che so di solito, non ho idea di come si possa farlo funzionare. Forse puoi provare a @ Ishan070692's anwser. Se il tuo sito web non è troppo grande e non c'è motivo per questo layout specifico, ti suggerisco di rifattorizzare il tuo progetto, seguendo [Documentazione Django] (https://docs.djangoproject.com/en/1.6/intro/tutorial01/) consigli. Faciliterà il tuo processo di sviluppo e le persone saranno in grado di capire il tuo progetto e aiutarti più velocemente. –

+0

Grazie per questa grande spiegazione e soluzione! Stavo avendo un problema simile e questo non solo ha risolto, ma ha reso sensato. – Synthead

5

La ragione potrebbe essere che django sta cercando di cercare la directory dei modelli nella directory con il file setting.py Mentre in realtà la directory dei modelli si trova nella directory superiore. Prova a fare qualcosa di simile nelle tue impostazioni.py

SETTINGS_PATH = os.path.dirname(__file__) 
PROJECT PATH = os.path.join(SETTINGS_PATH, os.pardir) 
PROJECT_PATH = os.path.abspath(PROJECT_PATH) 
TEMPLATES_PATH = os.path.join(PROJECT_PATH, "templates") 

TEMPLATE_DIRS = (
    TEMPLATES_PATH, 
) 

L'errore è di solito a causa di modelli configurato in modo errato directory

Problemi correlati