Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 错误消息:未配置DjangoTemplates后端_Python_Django_Installation - Fatal编程技术网

Python 错误消息:未配置DjangoTemplates后端

Python 错误消息:未配置DjangoTemplates后端,python,django,installation,Python,Django,Installation,我是一个5-6年前用过一点Django的老家伙。一位朋友帮我开发了一个小程序来满足我的需要,这个工具的灵活性给我留下了深刻的印象。一年后,不再需要了,所以我停止使用它 今天,回到Django,我花了一天时间来了解如何在Windows 10上重新安装Python和Django,并用我用来学习的不同旧代码(学校案例练习效果良好)测试了Django。 我仍然有文件(代码、模板、输入和输出),但收到一条错误消息。 我想这条消息可能来自语法的更改(新版本??)或不完整的安装。作为参考,我从Notepad+

我是一个5-6年前用过一点Django的老家伙。一位朋友帮我开发了一个小程序来满足我的需要,这个工具的灵活性给我留下了深刻的印象。一年后,不再需要了,所以我停止使用它

今天,回到Django,我花了一天时间来了解如何在Windows 10上重新安装Python和Django,并用我用来学习的不同旧代码(学校案例练习效果良好)测试了Django。 我仍然有文件(代码、模板、输入和输出),但收到一条错误消息。 我想这条消息可能来自语法的更改(新版本??)或不完整的安装。作为参考,我从Notepad++运行我的程序

我不明白的是,为什么错误消息会引用像“base.py”这样的文件

对于一个专家来说,也许解决这个问题很容易,但对我来说,这就像攀登珠穆朗玛峰一样。 所以,如果有人有想法,我会非常感激。 多谢各位

为了提供帮助,我准备了一些信息

1/

 - _ code
   _ errors messages (at running)
   _ template
   _ input
   _ output (I got before)
 - _ Installation of Python and Django (commands I used)
2/

 - _ code
   _ errors messages (at running)
   _ template
   _ input
   _ output (I got before)
 - _ Installation of Python and Django (commands I used)
非常感谢你的帮助

1/..== ==代码(文件:main.py)====

===========================

==运行(main.py)和错误消息====

Python 3.7.7 (tags/v3.7.7:d7c567b08f, Mar 10 2020, 10:41:24) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> 
============ RESTART: F:\recherche code Python\test_meeting3\main.py ===========
{'title': 'Excellent ! Félicitations ! ', 'titleNote': "I deleted comment11 et comment12 ('Empty' ,nothing in cell, in  pics.txt)", 'commentBottom1': 'Ceci est un nouveau commentaire', 'commentBottom2': 'Nouveau comment2', 'pics': [{'comment1': '', 'comment2': '', 'linkext': 'pict/nopict.png', 'linklocal': 'pict/nopict.png', 'comment3': "comment31éùÉê'est"}, {'comment1': 'Ceci est mon commentaire :', 'comment2': 'Le programme fonctionne bien', 'linkext': 'http://amolife.com/image/images/stories/beautiful%20birds/beautiful-birds-1.jpg', 'linklocal': 'pict/pict8.jpg', 'comment3': "comment32éùÉê'est"}, {'comment1': "comment13éùÉê'est", 'comment2': "comment23éùÉê'est", 'linkext': 'http://www.google.ca/imgres?imgurl=http%3A%2F%2Fstatic.squarespace.com%2Fstatic%2F50392129c4aa2c5a0b86bd15%2F50392129c4aa2c5a0b86bd27%2F5039251ac4aa2c5a0b86c275%2F1345922330960%2Fcbm1.jpeg&imgrefurl=http%3A%2F%2Fwww.companionbirdsministries.com%2F&h=300&w=590&tbnid=Kc0MRAGD30P6SM%3A&zoom=1&docid=DRtvtVIYyeX4UM&ei=KhmeVJynN8qiyASVx4KoAw&tbm=isch&ved=0CCQQMygJMAk&iact=rc&uact=3&dur=1581&page=1&start=0&ndsp=15', 'linklocal': 'pict/pict9.jpg', 'comment3': "comment33éùÉê'est"}]}
Traceback (most recent call last):
  File "F:\recherche code Python\test_meeting3\main.py", line 37, in <module>
    t = Template(template_str) # Django Template object
  File "C:\Python37\lib\site-packages\django\template\base.py", line 149, in __init__
    engine = Engine.get_default()
  File "C:\Python37\lib\site-packages\django\template\engine.py", line 79, in get_default
    raise ImproperlyConfigured('No DjangoTemplates backend is configured.')
django.core.exceptions.ImproperlyConfigured: No DjangoTemplates backend is configured.
>>>
win32上的Python 3.7.7(tags/v3.7.7:d7c567b08f,2020年3月10日,10:41:24)[MSC v.1900 64位(AMD64)] 有关详细信息,请键入“帮助”、“版权”、“信用证”或“许可证()。 >>> =========重新启动:F:\recherche code Python\test\u meeting3\main.py=========== {'title':'excelled!Félications!','titleNote':“我删除了comment11 et comment12('Empty',单元格中没有任何内容,在pics.txt中)”,'commentBottom1':'Ceci est un nouveau commentaire','commentBottom2':'nouveau comment2','pics':[{'comment1':','comment2','linkext:'pict/nopict.png','linklocal:'pict/nopict.png','comment3':“comment31ùùùùôôôôôôôôôôôôôôôôhttp://amolife.com/image/images/stories/beautiful%20birds/beautiful-birds-1.jpg、'linklocal':'pict/pict8.jpg、'comment3':'comment32ùùùùùùùùùùùùùùùùùùù",'linkext':'http://www.google.ca/imgres?imgurl=http%3A%2F%2Fstatic.squarespace.com%2Fstatic%2F50392129c4aa2c5a0b86bd15%2F50392129c4aa2c5a0b86bd27%2F5039251ac4aa2c5a0b86c275%2F1345922330960%2Fcbm1.jpeg&imgrefurl=http%3A%2F%2Fwww.companionbirdsministries.com%2F&h=300&w=590&tbnid=Kc0MRAGD30P6SM%3A&zoom=1&docid=DRtvtVIYyeX4UM&ei=KhmeVJynN8qiyASVx4KoAw&tbm=isch&ved=0CQQMYGJMAK&iact=rc&uact=3&dur=1581&page=1&start=0&ndsp=15','linklocal':'pict/pict9.jpg','comment3':'comment33ùùùùest'} 回溯(最近一次呼叫最后一次): 文件“F:\recherche code Python\test\u meeting3\main.py”,第37行,在 t=模板(模板_str)#Django模板对象 文件“C:\Python37\lib\site packages\django\template\base.py”,第149行,在\uuu init中__ engine=engine.get_default() 文件“C:\Python37\lib\site packages\django\template\engine.py”,第79行,默认为get\u raise配置不正确('未配置DjangoTemplates后端') django.core.exceptions.ImpropertlyConfigured:未配置DjangoTemplates后端。 >>> ==================  ==template.html===

<!DOCTYPE html>
<html lang="eng">
<head id="page_header">
                <title>Test Python</title>
                <meta charset="utf-8"/>
                <link href="exo_test.css" rel="stylesheet" type="text/css" />

</head>
<body >
<!-- id_title -->
<div id="id_title">
        <!-- id_title_up -->
        <div id="id_title_up" align="left" >
                <h2 >
                {{ title }}</BR>
                </h2>
                <a><font size="2" color="white">
                {{ titleNote }}    </BR></font>
        </div>
<!-- End id_title_up -->
</div>

<!-- frame for displaying pict -->
<div id="id_frame_pict">
  <!-- n pict -->
  {% for pic in pics %}
<pre> {{ pic.comment1 }}
 {{ pic.comment2 }}
    <a href="{{ pic.linkext }}" target="blank"><img src="{{ pic.linklocal }}" width="50" alt="No pict"/></a><span style="color: #5500ff;">   {{ pic.comment3 }}</span></pre>
    <a>----------------------------------------------------------</a>
  {% endfor %}
<!-- end of n pict-->
</div>
<!-- en of frame for displaying pict --
<!--%%%%% Comment end of page %%%%%%%%-->
<div id="id_frame_bottom">
                <a><font size="3" color="red">
                {{ commentBottom1 }}    </BR></font>
                <a><font size="2" color="grey">
                {{ commentBottom2 }}    </BR></font>
<!--%% End of comment end of page %%-->
</div>
</body>
</html>

测试Python
{{title}}
{{pic.comment3}} 评注31ùùùùùùùùùùùùù249;美国东部时间 评论32ùùùùùùùùùùùùù24;美国东部时间 评注33ùùùùùùùùùùùùù249;美国东部时间

2/Windows 10安装=== W10-Python和Django****

=======================
Python安装:
下载安装程序:https://www.python.org/downloads/
安装Python
双击下载的文件并按照安装提示进行操作
选中标有“将Python添加到路径”的框
“选择安装”
检查:所有用户
C:\Python37
命令:
(安装e版)
py-3-V
(安装虚拟环境工具)
pip3安装VirtualVWrapper win
(为Django创建虚拟环境)
mkvirtualenv开发工作包
(激活虚拟环境)
修井开发工作包
停用-退出当前Python虚拟环境
workon-列出可用的虚拟环境
workon name_of_environment-激活指定的Python虚拟环境
rmvirtualenv name_of_environment-删除指定的环境。
安装Django:
pip3安装django
检查安装:
py-mdjango--version(或:py-3-mdjango--version)
===================== 
项目:
=========== 
创建文件夹:
mkdir测验pq
cd测验pq
===========
从记事本++启动Python:
运行-->路径:C:\Python37\Lib\idlelib\idle.py“$(完整\u当前\u路径)”
(Ctrl+shift+向右箭头)
--错误:来自django.conf:没有名为“django”的模块==?
副指挥官:
C:\Users\user1>pip冻结
appdirs==1.4.3
distlib==0.3.0
filelock==3.0.12
importlib元数据==1.6.0
六=1.14.0
virtualenv==20.0.17
虚拟说唱歌手赢==1.2.6
ZIP==3.1.0
C:\Users\user1>python
win32上的Python 3.7.7(tags/v3.7.7:d7c567b08f,2020年3月10日,10:41:24)[MSC v.1900 64位(AMD64)]
有关详细信息,请键入“帮助”、“版权”、“信用证”或“许可证”。
>>>进口django
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
ModuleNotFoundError:没有名为“django”的模块
>>>
----解决方案------
安装Django:
pip安装django
升级pip:
python-mpip安装——升级pip
验证安装:
django管理--版本
verif安装:
C:\Users\user1>django管理员--版本
3.0.5
===========
<
 =======================
    Python installation :
    Download installer : https://www.python.org/downloads/
    Install Python 
       double-clicking on the downloaded file and following the installation prompts
          Check the box labeled "Add Python to PATH"
          "Choose installation"
              check : all users
              C:\Python37
    cmd :
    (version installée)
    py -3 -V   
    (install virtual environment tool)
    pip3 install virtualenvwrapper-win 
    (create a virtual environment for Django)
    mkvirtualenv dev-wp 
    (activate virtal environment)
    workon dev-wp 
                deactivate — Exit out of the current Python virtual environment
                workon — List available virtual environments
                workon name_of_environment — Activate the specified Python virtual environment
                rmvirtualenv name_of_environment — Remove the specified environment. 
    Install Django :
    pip3 install django
    check installation :
    py -m django --version (or : py -3 -m django --version )

    ===================== 
    project :
    =========== 
    create a folder :
    mkdir quiz-pq
    cd quiz-pq

    ===========
    launch Python from notepad++ :
    run --> path :   C:\Python37\Lib\idlelib\idle.py "$(FULL_CURRENT_PATH)"
    (Ctrl + shift + arrow right)

    -- error : from django.conf : no module named 'django'===? 
    sous cmd : 

    C:\Users\user1>pip freeze
    appdirs==1.4.3
    distlib==0.3.0
    filelock==3.0.12
    importlib-metadata==1.6.0
    six==1.14.0
    virtualenv==20.0.17
    virtualenvwrapper-win==1.2.6
    zipp==3.1.0

    C:\Users\user1>python
    Python 3.7.7 (tags/v3.7.7:d7c567b08f, Mar 10 2020, 10:41:24) [MSC v.1900 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import django
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ModuleNotFoundError: No module named 'django'
    >>>
    ---- solution ------- 
    install Django :
    pip install django
    updgrade pip :
    python -m pip install --upgrade pip
    verify install : 
    django-admin --version
    verif install :
    C:\Users\user1>django-admin --version
    3.0.5
===========
settings.configure()       # Set-up Django before using its functionalities
django.setup()
t = Template(template_str) # Django Template object
c = Context(DATA)     # Django Context object
final_xml = t.render(c)   # returns a Python string
TEMPLATES = [                           # Setup Django templates backend 
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': ['/path/to/template'],
    }
]
settings.configure(TEMPLATES=TEMPLATES) 
django.setup()                          # Set-up Django before using its functionalities
t = Template(template_str)              # Django Template object
c = Context(DATA)                       # Django Context object
final_xml = t.render(c)                 # returns a Python string