相关疑难解决方法(0)

在python中生成HTML文档

在python中,生成HTML文档的最优雅方式是什么.我目前手动将所有标签附加到一个巨大的字符串,并将其写入文件.有更优雅的方式吗?

html python

57
推荐指数
5
解决办法
7万
查看次数

如何在没有服务器的情况下使用Django模板

我纯粹使用Django来创建模板(没有服务器).这是我的计划:

page1.html

{% extends "base.html" %}
{% block 'body' %}

    <div class="container">
        <img src="./images/{{filename}}" style="padding-top:100px; padding-left:100px" align="center" width="60%" heig
    </div>

{% endblock %}
Run Code Online (Sandbox Code Playgroud)

base.html文件

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <link rel="stylesheet" type="text/css" href="../src/bootstrap.min.css">
        <link rel="stylesheet" type="text/css" href="../src/sticky-footer-navbar.css">
        <link rel="icon" href="../images/favicon.ico">

        <title>MY TITLE</title>

    </head>
    <body>


 <!-- Fixed navbar -->
    <nav class="navbar navbar-default navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" …
Run Code Online (Sandbox Code Playgroud)

python django django-templates

8
推荐指数
1
解决办法
381
查看次数

Django 错误:未配置 DjangoTemplates 后端

我正在使用 Django,我需要从给定的模板 (lab.html) 动态生成一个 HTML 文件:

from django.template import Template, Context
from django.conf import settings

settings.configure()
f = qc.QFile('lab.html')
f.open(qc.QFile.ReadOnly | qc.QFile.Text)
stream = qc.QTextStream(f)
template = stream.readAll()
print(template)
f.close()

t = Template(template)
c = Context({"result": "test"}) #result is the variable in the html file that I am trying to replace
Run Code Online (Sandbox Code Playgroud)

但是,我不断收到这个奇怪的错误,经过一些研究,我在任何地方都找不到。有什么想法吗?

Traceback (most recent call last):
  File "/Users/gustavorangel/PycharmProjects/help/HelpUI.py", line 262, in filesSearch
    t = Template(template)

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/template/base.py", line 184, in __init__
    engine = Engine.get_default()

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/template/engine.py", line 83, in …
Run Code Online (Sandbox Code Playgroud)

python django

6
推荐指数
1
解决办法
4002
查看次数

使用Django的模板引擎,而不使用Django的其余部分

我正在构建一个应用程序,它使用Django模板引擎/语言来"编译"一些HTML.但是,该应用程序不能在Django上运行,并且没有所有的配置和东西.当我尝试使用它时,我收到以下错误:

Traceback (most recent call last):
  File "Send.py", line 33, in <module>
    template = loader.get_template("email.html")
  File "/Library/Python/2.7/site-packages/django/template/loader.py", line 157, in get_template
    template, origin = find_template(template_name)
  File "/Library/Python/2.7/site-packages/django/template/loader.py", line 138, in find_template
    raise TemplateDoesNotExist(name)
django.template.base.TemplateDoesNotExist: email.html
Run Code Online (Sandbox Code Playgroud)

我使用的代码如下:

from django.template import loader, Context
from django.conf import settings

template = loader.get_template("email.html")
rendered = template.render(data)
Run Code Online (Sandbox Code Playgroud)

该模板与Python文件位于同一目录中.

python django templates

5
推荐指数
2
解决办法
2225
查看次数

标签 统计

python ×4

django ×3

django-templates ×1

html ×1

templates ×1