0

i'm new in this sphere, and i just for now create new project django. every looks good, but when i in views.py set page, there is say it's not find. Help!

my /my_test/get_key/views.py

from django.shortcuts import render
from django.http import HttpResponse
from django.template import RequestContext, loader

def index(request):
    template = loader.get_template('./index.html')
    context = RequestContext(request, {
    })
    return HttpResponse(template.render(context))

my /my_test/get_key/urls.py

from django.conf.urls import patterns, url

from get_key import views

urlpatterns = patterns('',
    url(r'^$', views.index, name='index')
)

my /my_test/my_test/urls.py

from django.conf.urls import patterns, include, url

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'my_test.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),
    url(r'', include('get_key.urls')),
    url(r'^admin/', include(admin.site.urls)),
)

my /my_test/my_test/settenings.py

import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
TEMPLATE_DIRS = (
    os.path.join(BASE_DIR, '/'),
)

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '3q_x$&q%e)g#*i)b2*r^g(0m*@q=urwe@0h==x8n1o416@h96x'

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

TEMPLATE_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',
    'get_key',
)

MIDDLEWARE_CLASSES = (
    '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',
)

ROOT_URLCONF = 'my_test.urls'

WSGI_APPLICATION = 'my_test.wsgi.application'


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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'my_test',
        'USER': 'root',
        'PASSWORD': 'test',
        'HOST': '127.0.0.1',
        'PORT': '3306',
        'OPTIONS': {
                'init_command': 'SET storage_engine=INNODB'
        }

    }
}
LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/

STATIC_URL = '/static/'
oliloshka
  • 11
  • 1
  • 7
  • What's the actual error? – Henrik Andersson Oct 24 '14 at 10:12
  • TemplateDoesNotExist at / ./index.html Request Method: GET Request URL: http://127.0.0.1:8000/ Django Version: 1.6.6 Exception Type: TemplateDoesNotExist Exception Value: ./index.html – oliloshka Oct 24 '14 at 10:13
  • 1
    Please post your settings. Maybe you did not set your TEMPLATE_DIRS (it is not set by default). See: https://docs.djangoproject.com/en/1.7/ref/settings/#template-dirs – Bjorn Oct 24 '14 at 10:14
  • Also, don't use `./` in your template path: just use "index.html". – Daniel Roseman Oct 24 '14 at 10:16
  • So where are the templates? That setting doesn't look right, aren't they in a directory called something like "templates"? – Daniel Roseman Oct 24 '14 at 10:18
  • i put file to /my_test/get_keys/index.html, it;s wrong? – oliloshka Oct 24 '14 at 10:19
  • 2
    @oliloshka You need to put all the templates in a folder called "templates"(or whatever you want) then you have to mention it's path in settings.py file for `TEMPLATE_DIRS` Got it ? Django can't locate your index.html so you are getting that error – d-coder Oct 24 '14 at 10:39

1 Answers1

0

you can see this Q

Django staticfiles app help

clear know the STATIC_ROOT and read the docs detail is import.

Community
  • 1
  • 1
orangleliu
  • 752
  • 5
  • 6