简体   繁体   English

在Django中提供static index.html

[英]Serving static index.html in django

Thing is, I have an angular + cordova app on one module. 问题是,我在一个模块上有一个angular + cordova应用程序。 I just want the REST api from django for the webserver. 我只想要django的REST API作为网络服务器。 no views or anything (well only to serve the angular views). 没有视图或任何东西(只能用于角度视图)。

How can I serve the static index.html using django? 如何使用Django提供静态index.html? do I need different project structure? 我需要不同的项目结构吗? I'm a newbie to django. 我是django的新手。

Thanks in advance! 提前致谢!

这让我发疯。

You can use TemplateView directly: 您可以直接使用TemplateView

from django.views.generic import TemplateView

...
url(r'^$', TemplateView.as_view(template_name='index.html'))

Remember you need to configure your templates folder to call .html files by name only. 请记住,您需要将模板文件夹配置为仅按名称调用.html文件。

First, place this index.html page in your server/templates folder so Django knows about it. 首先,将此index.html页面放置在server / templates文件夹中,以便Django知道。

Then, do this in your URLs.py: 然后,在您的URLs.py中执行以下操作:

from django.views.generic import TemplateView

urlpatterns = [
    url(r'^$', TemplateView.as_view(template_name='index.html')),
]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM