我做了一个项目,我想在PythonAnywhere上托管这个项目,但是如果我运行我的应用程序,我会遇到模板不存在的错误。
设置.py
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-_5&ew#uj!u(kjfmo7b@nxh9=o6fg4!8t3u2a9yj*@vti2u7i^u'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['manojgupta143.pythonanywhere.com']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'Blog',
'taggit',
]
这是我的设置文件,我fefined我的模板设置
我的模板文件夹所在的文件夹结构:
/home/manojgupta143/Blog-project-with-django/templates/blog
如果我运行网页我有这些类型的错误
ImportError at /
Module "django.template.backends.django" does not define a "Django/Templates" attribute/class
Request Method: GET
Request URL: http://manojgupta143.pythonanywhere.com/
Django Version: 3.2
Exception Type: ImportError
Exception Value:
Module "django.template.backends.django" does not define a "Django/Templates" attribute/class
Exception Location: /home/manojgupta143/.virtualenvs/myproj/lib/python3.9/site-packages/django/utils/module_loading.py, line 22, in import_string
Python Executable: /usr/local/bin/uwsgi
Python Version: 3.9.5
Python Path:
['/home/manojgupta143/Blog-project-with-django/',
'/var/www',
'.',
'',
'/var/www',
'/usr/local/lib/python39.zip',
'/usr/local/lib/python3.9',
'/usr/local/lib/python3.9/lib-dynload',
'/home/manojgupta143/.virtualenvs/myproj/lib/python3.9/site-packages']
Server time: Sat, 05 Feb 2022 07:59:23 +0000
网页配置
Source code:
/home/manojgupta143/Blog-project-with-django/ Go to directory
Working directory:/home/manojgupta143/
WSGI configuration file:/var/www/manojgupta143_pythonanywhere_com_wsgi.py
Python version: 3.9
wsgi.py
# +++++++++++ DJANGO +++++++++++
# To use your own django app use code like this:
import os
import sys
#
## assuming your django settings file is at '/home/manojgupta143/mysite/mysite/settings.py'
## and your manage.py is is at '/home/manojgupta143/mysite/manage.py'
path = '/home/manojgupta143/Blog-project-with-django/'
if path not in sys.path:
sys.path.insert(0, path)
#os.environ.setdefault('DJANGO_SETTINGS_MODULE','/Blogproject.settings')
os.environ['DJANGO_SETTINGS_MODULE'] = 'Blogproject.settings'
#
## then:
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
第一次当我尝试运行,然后我得到了错误模板noy存在。现在它呈现一个新的错误。
2条答案
按热度按时间mkh04yzy1#
确保您已经在www.example.com中定义了TEMPLATES URLsettings.py
azpvetkf2#
我也遇到过类似的问题,但我通过在正确的目录中更改模板成功解决了这个问题。
因此,添加一些更多的上下文,确保您将模板文件夹添加到主目录中,而不是像在VS代码中那样添加项目文件夹。
示例****不要这样做
项目名称
相反,对这个。
项目名称
给予一试,希望这能起作用。