我试图在我的域中创建一个博客,使用django 1.9和python 3.5与虚拟环境。在部署Python Anywhere时。我可以渲染HTML。这里是traceback。
第一个月Request URL: http://www.example.com/
个Django Version: 1.9
个Python Version: 3.5.2
个Installed Applications:
个
['django.contrib.admin', `
` 'django.contrib.auth', `
`'django.contrib.contenttypes',`
`'django.contrib.sessions',`
`'django.contrib.messages',`
`'django.contrib.staticfiles',`
`'blog']``
字符串Installed Middleware:
个['django.middleware.security.SecurityMiddleware',
个'django.contrib.sessions.middleware.SessionMiddleware',
个'django.middleware.common.CommonMiddleware',
个'django.middleware.csrf.CsrfViewMiddleware',
个'django.contrib.auth.middleware.AuthenticationMiddleware',
个'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
个'django.contrib.messages.middleware.MessageMiddleware',
个'django.middleware.clickjacking.XFrameOptionsMiddleware']
个Template loader postmortem
个Django tried loading these templates, in this order:
个
Using engine django:
* django.template.loaders.app_directories.Loader:
/home/pdlsaroj22/.virtualenvs/venv/lib/python3.5/site-packages/django/contrib/admin/templates/blog/templates/blog/post/list.html(Source does not exist)
* django.template.loaders.app_directories.Loader:
/home/pdlsaroj22/.virtualenvs/venv/lib/python3.5/site-packages/django/contrib/auth/templates/blog/templates/blog/post/list.html(Source does not exist)
* django.template.loaders.app_directories.Loader:
/home/pdlsaroj22/myblog/mysite/blog/templates/blog/templates/blog/post/list.html (Source does not exist)
Using engine django:
* django.template.loaders.app_directories.Loader:
/home/pdlsaroj22/.virtualenvs/venv/lib/python3.5/site-packages/django/contrib/admin/templates/blog/post_list.html (Source does not exist)
* django.template.loaders.app_directories.Loader:
/home/pdlsaroj22/.virtualenvs/venv/lib/python3.5/site-packages/django/contrib/auth/templates/blog/post_list.html (Source does not exist)
* django.template.loaders.app_directories.Loader:
/home/pdlsaroj22/myblog/mysite/blog/templates/blog/post_list.html (Source does not exist)
型
回溯:
File "/home/pdlsaroj22/.virtualenvs/venv/lib/python3.5/site-packages/django/core/handlers/base.py" in get_response
response = `self.process_exception_by_middleware(e, request)
File "/home/pdlsaroj22/.virtualenvs/venv/lib/python3.5/site-packages/django/core/handlers/base.py" in get_response
response = response.render()
File "/home/pdlsaroj22/.virtualenvs/venv/lib/python3.5/site-packages/django/template/response.py" in render
self.content = self.rendered_content
File "/home/pdlsaroj22/.virtualenvs/venv/lib/python3.5/site-packages/django/template/response.py" in rendered_content
template = self._resolve_template(self.template_name)
File "/home/pdlsaroj22/.virtualenvs/venv/lib/python3.5/site-packages/django/template/response.py" in _resolve_template
new_template = self.resolve_template(template)
File "/home/pdlsaroj22/.virtualenvs/venv/lib/python3.5/site-packages/django/template/response.py" in resolve_template
return select_template(template, using=self.using)
File "/home/pdlsaroj22/.virtualenvs/venv/lib/python3.5/site-packages/django/template/loader.py" in select_template
raise TemplateDoesNotExist(', '.join(template_name_list), chain=chain)
Exception Type: TemplateDoesNotExist at /
Exception Value: blog/templates/blog/post/list.html, blog/post_list.html
型
我的views.py看起来像这样:
class PostListView(ListView):
queryset = Post.published.all()
context_object_name = 'posts'
paginate_by = 3
template_name = 'blog/templates/blog/post/list.html'
型
3条答案
按热度按时间aemubtdh1#
如果你有一个名为blog的应用程序(在settings.py中注册),并且你在settings.py中的模板目录下将APP_DIR设置为true,那么很可能你的blog应用程序中有一个名为templates的目录,而在templates中有另一个名为blog的目录。
如果是这样的话,那么
blog/templates/blog/post/list.html
实际上应该写成:post/list.html
前提是您在博客应用程序的博客目录中有一个post目录。nwsw7zdq2#
你必须使文件夹命名为
"templates"
在settingd.py
驻留,并把你的.html文件在这个模板文件夹.并在以下settings.py
文件中进行更改:字符串
在你的代码中做如下修改:
型
希望这个答案对你有帮助。
ppcbkaq53#
您只需重定向到正确的模板目录。我的模板是在文件夹'templates'在根文件夹(同一文件夹包含manage.py).
此设置显示了相同的错误:
字符串
所以,我把它改成了这个:
型
而且成功了!顺便说一句,“约会”是我项目的名字。
在pythonanywhere中,你应该在/前面加上你的项目名,因为那个文件夹就是你的新家。