新项目django的问题

时间:2014-10-24 10:09:57

标签: python django

我是这个领域的新手,我现在只是创建新项目django。 每一个看起来都很好,但是当我在views.py设置页面时,有人说它找不到。救命啊!

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/'

1 个答案:

答案 0 :(得分:0)

你可以看到这个Q

Django staticfiles app help

清楚知道STATIC_ROOT并阅读文档详细信息是导入。