【发布时间】:2016-12-09 04:43:02
【问题描述】:
问题:
运行时django startproject manage.py
当我将路径打印到终端时,我收到以下错误:
Traceback (most recent call last):
File "pathdjango\core\handlers\exception.py", line 39, in inner
response = get_response(request)
File "pathdjango\core\handlers\base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "pathdjango\core\handlers\base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "fullpathprojects\demo\csdemo\csdemo\views.py", line 6, in index
return render(request,'templates/index.html')
File "pathdjango\shortcuts.py", line 30, in render
content = loader.render_to_string(template_name, context, request, using=using)
File "pathdjango\template\loader.py", line 67, in render_to_string
template = get_template(template_name, using=using)
File "pathdjango\template\loader.py", line 21, in get_template
return engine.get_template(template_name)
File "pathdjango\template\backends\django.py", line 39, in get_template
return Template(self.engine.get_template(template_name), self)
File "pathdjango\template\engine.py", line 160, in get_template
template, origin = self.find_template(template_name)
File "pathdjango\template\engine.py", line 134, in find_template
name, template_dirs=dirs, skip=skip,
File "pathdjango\template\loaders\base.py", line 38, in get_template
contents = self.get_contents(origin)
File "pathdjango\template\loaders\filesystem.py", line 24, in get_contents
with io.open(origin.name, encoding=self.engine.file_charset) as fp:
IOError: [Errno 22] Invalid argument: u'fullpath\\demo\\csdemo\\:\\templates\\index.html'
我不知道为什么路径中间有一个“:”。
我正在关注本教程以供参考here:
什么有效:
我可以查看管理员。
背景:
我正在使用 Microsoft Windows 10 并使用 anaconda
使用 django 和虚拟环境我有一个 django 项目:
项目/演示/
在演示中我有以下文件夹:
演示 静止的 模板 管理.py
在模板中,我使用浏览器检查并加载了 index.html 文件。
在项目/演示/演示中我有 settings.py、urls.py、views.py
以下是我所做的与该问题相关的主要编辑:
在 settings.py 中:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': os.path.join(BASE_DIR,'demo\\template\\'),
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
文件的路径是正确的。
在 urls.py 中:
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^index/',views.index)
]
在views.py中
def index(request):
return render(request,'templates/index.html',{})
【问题讨论】:
-
请将完整的错误回溯添加到您的问题中。