Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/347.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.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 如何从django中的diff目录提供html文件_Python_Django - Fatal编程技术网

Python 如何从django中的diff目录提供html文件

Python 如何从django中的diff目录提供html文件,python,django,Python,Django,我需要做一个应用程序,我有现成的独立html模板在我的 app/ready\u模板/template1 现在,我已经创建了一个视图,其中显示了要向用户显示的模板的名称和缩略图 但是有一个演示链接,我想让他们看到整个模板 {% load static from staticfiles %} <a href="{% static "template1/index.html" %}" />template1</a> 基本上,如果他们点击演示,那么我想将他们重定向到 templ

我需要做一个应用程序,我有现成的独立html模板在我的

app/ready\u模板/template1

现在,我已经创建了一个视图,其中显示了要向用户显示的模板的名称和缩略图

但是有一个演示链接,我想让他们看到整个模板

{% load static from staticfiles %}
<a href="{% static "template1/index.html" %}" />template1</a>
基本上,如果他们点击演示,那么我想将他们重定向到


template1/index.html
这样他们就可以看到所有模板、图像、js等,而无需将任何内容链接到django视图

,因此您的需求看起来非常简单。您可以使用Django中的特性来实现这一点。基本上,只要你有一堆静态内容,比如html、css、js图像,你就把它们放在应用程序中名为
static
的文件夹中。例如,Django附带的管理应用程序在
Django/contrib/admin/static
中包含所有的静态内容。然后,您可以在django模板中放置下面这样的简单内容,以链接到静态内容。当然,您不必像template1那样硬编码每个名称,您可以在django模板中动态生成它

{% load static from staticfiles %}
<a href="{% static "template1/index.html" %}" />template1</a>
{%loadstaticfromstaticfiles%}

所以你的意思是我在我的应用程序中复制模板,比如
app/static/template1
app/static/template2
。然后,他们将自动从那里服务。现在模板中会有更多的html文件,比如aboutu.html、conatct.html。也将从那里送达。这是正确的。如果是静态内容,则应将其放置在静态中。如果它们是动态的django模板,那就另当别论了