命令行调试Django的Template功能时碰到的问题及解决方案
2016-03-19 20:10
691 查看
背景:正常安装python和Django,python命令行执行如下命令报错
C:\Users\Heyn>python
Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> from django.template import Template, Context
>>> t = Template('Hello, {{ name }}')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\django\template\base.py", line 182, in __i
nit__
engine = Engine.get_default()
File "C:\Python27\lib\site-packages\django\utils\lru_cache.py", line 124, in w
rapper
result = user_function(*args, **kwds)
File "C:\Python27\lib\site-packages\django\template\engine.py", line 88, in ge
t_default
django_engines = [engine for engine in engines.all()
File "C:\Python27\lib\site-packages\django\template\utils.py", line 110, in al
l
return [self[alias] for alias in self]
File "C:\Python27\lib\site-packages\django\template\utils.py", line 107, in __
iter__
return iter(self.templates)
File "C:\Python27\lib\site-packages\django\utils\functional.py", line 33, in _
_get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Python27\lib\site-packages\django\template\utils.py", line 31, in tem
plates
self._templates = settings.TEMPLATES
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 55, in __ge
tattr__
self._setup(name)
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 41, in _set
up
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting TEMPLATES, but se
ttings are not configured. You must either define the environment variable DJANG
O_SETTINGS_MODULE or call settings.configure() before accessing settings.
>>>
解决方案:
>>> from django.conf import settings
>>> settings.configure()
>>> import django
>>> django.setup()
C:\Users\Heyn>python
Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> from django.template import Template, Context
>>> t = Template('Hello, {{ name }}')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\django\template\base.py", line 182, in __i
nit__
engine = Engine.get_default()
File "C:\Python27\lib\site-packages\django\utils\lru_cache.py", line 124, in w
rapper
result = user_function(*args, **kwds)
File "C:\Python27\lib\site-packages\django\template\engine.py", line 88, in ge
t_default
django_engines = [engine for engine in engines.all()
File "C:\Python27\lib\site-packages\django\template\utils.py", line 110, in al
l
return [self[alias] for alias in self]
File "C:\Python27\lib\site-packages\django\template\utils.py", line 107, in __
iter__
return iter(self.templates)
File "C:\Python27\lib\site-packages\django\utils\functional.py", line 33, in _
_get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Python27\lib\site-packages\django\template\utils.py", line 31, in tem
plates
self._templates = settings.TEMPLATES
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 55, in __ge
tattr__
self._setup(name)
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 41, in _set
up
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting TEMPLATES, but se
ttings are not configured. You must either define the environment variable DJANG
O_SETTINGS_MODULE or call settings.configure() before accessing settings.
>>>
解决方案:
>>> from django.conf import settings
>>> settings.configure()
>>> import django
>>> django.setup()
相关文章推荐
- codeforces-Good Bye 2015-New Year and Domino
- 来自bit.ly的1.usa.gov数据
- Go 实现lamda、匿名函数和内联函数
- Go 多态功能实现
- 英文歌曲:God is a girl(上帝是女孩)
- boost::algorithm
- ZOJ 2975 Kinds of Fuwas
- Recommended Django Project Layout
- 源码下修改开机动画及开机logo
- pip工具快速安装Django模块
- 关于visibility的属性值visible,invisible,gone的区别
- 蓝桥杯竞赛准备:algorithm头文件的使用 及memset函数的使用
- Celery 在Django 环境下无法接收消息问题解决
- Hdu 3966-Aragorn's Story LCT,动态树
- 【NOIP2013模拟】Heaven Cow与God Bull
- (转)使用graphviz绘制流程图 - CoolJie - 博客园 good
- Django进阶篇【1】
- 11292 - Dragon of Loowater (Time limit: 1.000 seconds)
- go圣经笔记--第二章
- velocity和mangodb和apk的关联