1

我已经在这里完成了其他答案,但由于这是我的第一个项目,所以无法掌握如何解决这个问题的版本。我可以让 127.0.0.1:8000/admin 正常显示。

我收到此错误:

TemplateDoesNotExist at /join/home.html.
Request Method: GET
Request URL:    http://127.0.0.1:8000/
Django Version: 1.5.1
Exception Type: TemplateDoesNotExist
Exception Value:    /join/home.html.

home.html位于/Users/user/Desktop/mvp_landing/static/templates/join

在我的views.py我有这个:

from django.shortcuts import render_to_response, RequestContext

from .models import Join
from .forms import JoinForm


def home(request):
    form = JoinForm(request.POST or None)
    if form.is_valid():
        new_join = form.save(commit=False)
        new_join.save()
    return render_to_response('/join/home.html.', locals(), context_instance=RequestContext(request))

所以我应该对我在这里的东西没问题,settings.pyTEMPLATE_DIRS吧?:

TEMPLATE_DIRS = (
    os.path.join(os.path.dirname(os.path.dirname(__file__)), "static", "templates"),
)

这是整个settings.py(删除了数据库信息等):

import os

DEBUG = True
TEMPLATE_DEBUG = DEBUG


MEDIA_ROOT = os.path.join(os.path.dirname(os.path.dirname(__file__)), "static", "media")

MEDIA_URL = '/media/'

STATIC_ROOT =  os.path.join(os.path.dirname(os.path.dirname(__file__)), "static", "static-only")

STATIC_URL = '/static/'

STATICFILES_DIRS = (
    os.path.join(os.path.dirname(os.path.dirname(__file__)), "static", "static"),
)

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)


SECRET_KEY = 'xxxxxxxxxxx'

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

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    # Uncomment the next line for simple clickjacking protection:
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'mvp_landing.urls'

WSGI_APPLICATION = 'mvp_landing.wsgi.application'

TEMPLATE_DIRS = (
    os.path.join(os.path.dirname(os.path.dirname(__file__)), "static", "templates"),
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    'django.contrib.admindocs',
    'south',
    'join',
)   

urls.py是:

from django.conf.urls import patterns, include, url
from django.conf import settings
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    (r'static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT}),
    (r'media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
    url(r'^$', 'join.views.home', name='home'),

    # Uncomment the admin/doc line below to enable admin documentation:
    url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    url(r'^admin/', include(admin.site.urls)),
)

任何帮助表示赞赏,谢谢。

4

2 回答 2

2

删除视图模板字符串中的第一个斜杠。

于 2013-07-29T23:34:21.743 回答
2

您应该在此处修复路径:

return render_to_response('join/home.html', locals(), context_instance=RequestContext(request))

请注意我是如何删除/开头的以及尾随的.

希望这可以帮助

于 2013-07-29T23:34:28.633 回答