配置设置[Django]引入模版之后报错Requested setting TEMPLATE_DEBUG, but settings are not configured.
2013-05-08 20:25
525 查看
这几周笔者几篇文章介绍了改配置设置的文章. 关联文章的地址
明天正在试图敲写以下代码:
结果报了一大堆错误:
Traceback (most recent call last): File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/Django-1.5.dev20120922131713-py2.7.egg/django/template/base.py",
line 123, in __init__ if settings.TEMPLATE_DEBUG and origin is None: File "/usr/local/lib/python2.7/dist-packages/Django-1.5.dev20120922131713-py2.7.egg/django/conf/__init__.py", line 50, in __getattr__ self._setup(name) File "/usr/local/lib/python2.7/dist-packages/Django-1.5.dev20120922131713-py2.7.egg/django/conf/__init__.py", line 43, in _setup % (name, ENVIRONMENT_VARIABLE))django.core.exceptions.ImproperlyConfigured: Requested
每日一道理
春蚕死去了,但留下了华贵丝绸;蝴蝶死去了,但留下了漂亮的衣裳;画眉飞去了,但留下了美妙的歌声;花朵凋谢了,但留下了缕缕幽香;蜡烛燃尽了,但留下一片光明;雷雨过去了,但留下了七彩霓虹。
大致的看了一下,说是什么设置没有配置,须要配置环境变量。
可以用以下法方来理处:
在import之前参加一下代码入导settings:
问题就理处了。
当然,还有另两种种理处方案,在此之前,我们先来看一下为什么不引入setting会报错。
动启python有两种式方:python manage.py shell和python。
这两个命令 都市动启互交解释器,但是manage.py shell命令有一个要重的不同: 在动启解释器之前,它诉告Django应用 哪个设置文件。 Django框架的大部分子系统,包含模板系统,都依赖于配置文件;如果Django不晓得应用哪 个配置文件,这些系统将不能作工。
如果你想晓得,这里将向你解释它当面是如何作工的。 Django索搜DJANGO_SETTINGS_MODULE环境变 量,它被设置在settings.py中。例如,设假mysite在你的Python索搜径路中,那么 DJANGO_SETTINGS_MODULE应该被设置为:’mysite.settings’。
当你运行命令:python manage.py shell,它将动自帮你理处DJANGO_SETTINGS_MODULE。 在前当的这 些示例中,我们勉励你应用`` python manage.py shell``这个法方,这样可以去免你大费周章地去配置那些你 不熟习的环境变量。
随着你愈来愈熟习Django,你可能会向偏于弃废应用`` manage.py shell`` ,而是在你的配置文 件.bash_profile中手动添加 DJANGO_SETTINGS_MODULE这个环境变量。
所以,另两种理处方案就是:
1.应用python manage.py shell动启Python
2.在你的配置文 件.bash_profile中手动添加 DJANGO_SETTINGS_MODULE这个环境变量。
文章结束给大家分享下程序员的一些笑话语录:
看到有人回帖“不顶不是中国人”,他的本意是想让帖子沉了。
明天正在试图敲写以下代码:
>>> from django import template >>> t = template.Template('My name is {{ name }}.') >>> c = template.Context({'name': 'WHY'}) >>> print t.render(c) My name is WHY. >>> c = template.Context({'name': 'HuaHua'}) >>> print t.render(c) My name is HuaHua.
结果报了一大堆错误:
Traceback (most recent call last): File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/Django-1.5.dev20120922131713-py2.7.egg/django/template/base.py",
line 123, in __init__ if settings.TEMPLATE_DEBUG and origin is None: File "/usr/local/lib/python2.7/dist-packages/Django-1.5.dev20120922131713-py2.7.egg/django/conf/__init__.py", line 50, in __getattr__ self._setup(name) File "/usr/local/lib/python2.7/dist-packages/Django-1.5.dev20120922131713-py2.7.egg/django/conf/__init__.py", line 43, in _setup % (name, ENVIRONMENT_VARIABLE))django.core.exceptions.ImproperlyConfigured: Requested
每日一道理
春蚕死去了,但留下了华贵丝绸;蝴蝶死去了,但留下了漂亮的衣裳;画眉飞去了,但留下了美妙的歌声;花朵凋谢了,但留下了缕缕幽香;蜡烛燃尽了,但留下一片光明;雷雨过去了,但留下了七彩霓虹。
大致的看了一下,说是什么设置没有配置,须要配置环境变量。
可以用以下法方来理处:
在import之前参加一下代码入导settings:
>>> from django.conf import settings >>> settings.configure()
问题就理处了。
当然,还有另两种种理处方案,在此之前,我们先来看一下为什么不引入setting会报错。
动启python有两种式方:python manage.py shell和python。
这两个命令 都市动启互交解释器,但是manage.py shell命令有一个要重的不同: 在动启解释器之前,它诉告Django应用 哪个设置文件。 Django框架的大部分子系统,包含模板系统,都依赖于配置文件;如果Django不晓得应用哪 个配置文件,这些系统将不能作工。
如果你想晓得,这里将向你解释它当面是如何作工的。 Django索搜DJANGO_SETTINGS_MODULE环境变 量,它被设置在settings.py中。例如,设假mysite在你的Python索搜径路中,那么 DJANGO_SETTINGS_MODULE应该被设置为:’mysite.settings’。
当你运行命令:python manage.py shell,它将动自帮你理处DJANGO_SETTINGS_MODULE。 在前当的这 些示例中,我们勉励你应用`` python manage.py shell``这个法方,这样可以去免你大费周章地去配置那些你 不熟习的环境变量。
随着你愈来愈熟习Django,你可能会向偏于弃废应用`` manage.py shell`` ,而是在你的配置文 件.bash_profile中手动添加 DJANGO_SETTINGS_MODULE这个环境变量。
所以,另两种理处方案就是:
1.应用python manage.py shell动启Python
2.在你的配置文 件.bash_profile中手动添加 DJANGO_SETTINGS_MODULE这个环境变量。
文章结束给大家分享下程序员的一些笑话语录:
看到有人回帖“不顶不是中国人”,他的本意是想让帖子沉了。
相关文章推荐
- [Django]引入模版之后报错Requested setting TEMPLATE_DEBUG, but settings are not configured.
- [Django]引入模版之后报错Requested setting TEMPLATE_DEBUG, but settings are not configured.
- django模板报错:Requested setting TEMPLATE_DEBUG, but settings are not configured. You must either define
- django 新建项目报错:Requested setting INSTALLED_APPS, but settings are not configured.
- Requested setting TEMPLATE_DEBUG, but settings are not configured.
- django.core.exceptions.ImproperlyConfigured: Requested setting LOGGING_CONFIG, but settings are not
- Requested setting DATABASES, but settings are not configured. You must either define the environment
- Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured
- django模板报错Requested setting TEMPLATE_DEBUG, but settings are not configured. You must either define
- pycharm 中的 Requested setting CACHES, but settings are not configured.
- django中执行py报错Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured
- django.core.exceptions.ImproperlyConfigured: Requested setting TEMPLATE_DEBUG, but settings are not解
- django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE的解决办法
- Django 找不到模版报错" django.template.exceptions.TemplateDoesNotExist: index.html"
- Whoops! Sorry, but you are not allowed to perform the action requested.
- MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error
- django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE的解决办法
- MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error
- django-redis遇到MISCONF Redis is configured to save RDB snapshots, but is currently not able to persis
- 如何解决django配置settings时遇到Could not import settings 'conf.local'