测试应用程序中的错误/ TemplateDoesNotExist django 1.8+

时间:2015-09-01 10:02:33

标签: python django templates

我经历了this onesome more之类的早期查询。但找不到解决方案。问题与先前问题中提到的相同。我使用django - 1.8.1python 2.7

urls.py

from django.conf.urls import include, url
from django.contrib import admin
from mysite.myapp import views 
urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^$', views.helloWorld, name="HelloWorld"),

]

views.py

def helloWorld(request):
    """
    """
    return render("login.html", {})

settings.py

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
SECRET_KEY = ')j+s&4t((&gq#5%acu(jw-&!qyp004hal)yzic50d5a%au^qjz'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'mysite.myapp',
)

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

ROOT_URLCONF = 'mysite.urls'

TEMPLATES = [
    {    
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': ["/home/laxmikant/Work/mysite/mysite/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',
            ],
        },
    },
]

WSGI_APPLICATION = 'mysite.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

STATIC_URL = '/static/'

目录结构:

├── db.sqlite3
├── manage.py
└── mysite
    ├── __init__.py
    ├── myapp
    │   ├── admin.py
    │   ├── __init__.py
    │   ├── migrations
    │   │   └── __init__.py
    │   ├── models.py
    │   ├── tests.py
    │   └── views.py
    ├── settings.py
    ├── templates
    │   └── login.html
    ├── urls.py
    └── wsgi.py

1 个答案:

答案 0 :(得分:2)

您的问题是渲染调用,尝试调用此函数render(request, 'login.html', {}),必须这样做。