• django 模板报错


    "Requested setting TEMPLATE_DEBUG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings."

    1. 先导入settings  
    2.   
    3. >>> from django.conf import settings  
    4.   
    5. >>> settings.configure()  
    6.   
    7. >>> from django import template  
    8. >>> t = template.Template('My name is {{ name }}.')  
    9. >>> c = template.Context({'name': 'yixiaohan'})  
    10. >>> print t.render(c)  
    11. My name is yixiaohan.  
    12. >>> c = template.Context({'name': 'xiaowangge'})  
    13. >>> print t.render(c)  
    14. My name is xiaowangge.  
    15.   
    16. 解决方法二:  
    17.   
    18. 使用python manage.py shell启动 Python交互式解释器(实际上启动的是Ipython)  
    19.   
    20. python manage.py shell  
    21.   
    22. yixiaohan@ubuntu:~/djbk$ python manage.py shell  
    23. Python 2.7.3 (default, Aug  1 2012, 05:16:07)   
    24. Type "copyright", "credits" or "license" for more information.  
    25.   
    26. IPython 0.12.1 -- An enhanced Interactive Python.  
    27. ?         -> Introduction and overview of IPython's features.  
    28. %quickref -> Quick reference.  
    29. help      -> Python's own help system.  
    30. object?   -> Details about 'object', use 'object??' for extra details.   
    31.   
    32. In [1]: from django import template  
    33.   
    34. In [2]: t = template.Template("my name is {{ name }}")  
    35.   
    36. In [3]: c = template.Context({'name':'yixiaohan'})  
    37.   
    38. In [4]: rt = t.render(c)  
    39.   
    40. In [5]: rt  
    41. Out[5]: u'my name is yixiaohan'  
    42.   
    43. In [6]: print rt  
    44. my name is yixiaohan  
  • 相关阅读:
    移动web前端高效开发实践 读书笔记
    前端开发最佳实践-读书笔记
    frontend-Tips
    匿名函数的几种写法
    12个用得着的JQuery代码片段(转)
    tesseract-ocr 学习笔记(比网上的中文说明都详细)
    关于大数据的思考
    单片机实验的小记录~~PWM
    组建Redis集群遇到`GLIBC_2.14' not found和ps -ef 不显示用户名
    柔性数组(Redis源码学习)
  • 原文地址:https://www.cnblogs.com/kfx2007/p/3417436.html
Copyright © 2020-2023  润新知