首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >TemplateDoesNotExist at /join/join.join (Django)

TemplateDoesNotExist at /join/join.join (Django)
EN

Stack Overflow用户
提问于 2013-07-29 23:25:16
回答 2查看 1.1K关注 0票数 1

我已经在这里讨论了其他的答案,但无法掌握如何解决我的版本的这个问题,因为这是我的第一个项目。我可以得到127.0.0.1:8000/admin才能显示得很好。

我得到了一个错误:

代码语言:javascript
运行
复制
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中,我有这样的内容:

代码语言:javascript
运行
复制
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所做的一切感到满意,对吧?

代码语言:javascript
运行
复制
TEMPLATE_DIRS = (
    os.path.join(os.path.dirname(os.path.dirname(__file__)), "static", "templates"),
)

下面是整个settings.py(删除了db信息等):

代码语言:javascript
运行
复制
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是这样的:

代码语言:javascript
运行
复制
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)),
)

任何帮助都是非常感谢的,谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-07-29 23:34:28

你应该在这里修复这条路:

代码语言:javascript
运行
复制
return render_to_response('join/home.html', locals(), context_instance=RequestContext(request))

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

希望这能有所帮助

票数 2
EN

Stack Overflow用户

发布于 2013-07-29 23:34:21

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17935902

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档