0

我已经在虚拟环境中安装了带有 python3.3 的 django 1.6 ...当我使用 startproject 命令创建项目时,我得到以下信息:

"""
Django settings for ozo project.

For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))


# 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 = '***********************************'

# 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',
)

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 = 'ozo.urls'

WSGI_APPLICATION = 'ozo.wsgi.application'


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

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

# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/

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

我认为此文件中缺少一些设置。我已经使用 django 1.5 startproject 命令进行了测试,它的设置如下:

MEDIA_URL、STATIC_ROOT、LOGGING、TEMPLATE_DIRS ...等。

4

2 回答 2

1

默认项目模板在 Django 1.6 中进行了简化。您可以在 GitHub 上的提交消息中查看更改说明。如果您需要类似的设置MEDIA_URL,请添加它。

于 2013-11-06T23:35:07.450 回答
0

正如我们从 django 1.6 版本中看到的那样

https://github.com/django/django/blob/master/docs/releases/1.6.txt

简化的默认项目和应用程序模板

startproject:djadmin:和 :djadmin:使用的默认模板startapp 已经过简化和现代化。:doc:admin </ref/contrib/admin/index>现在在新项目中默认启用;:doc:sites </ref/contrib/sites>框架不再是。:ref:clickjacking prevention <clickjacking-prevention>现在打开,数据库默认为 SQLite。

如果默认模板不适合您的口味,您可以使用 :ref:custom project and app templates <custom-app-and-project-templates>

所以我们可以只创建一个app,比如django-admin.py startapp testapp,并创建templates/testapp目录。然后把html放到test/app/templates/testapp/test.html

我们可以像这样使用views.py中的html

def index(request):
    return render_to_response('testapp/test.html')

我们不应该在 settings.py 中添加任何内容。

于 2013-11-18T13:04:17.630 回答