2015-10-19 72 views
0

事情是,我在一個模塊上有一個角+ cordova應用程序。我只想從Django的Web服務器的REST api。沒有任何意見或任何東西(以及只爲角視圖服務)。在django中提供靜態index.html

如何使用django爲static index.html提供服務?我需要不同的項目結構嗎?我是django的新手。

在此先感謝!

This is driving me nuts.

+1

是否有可能爲你把這個index.html頁面在您的服務器/模板文件夾?編輯:順便說一下,對於REST api,最好不要返回HTML頁面(而是返回JSON對象)。所以只是爲了驗證,你希望你的REST api服務於一個html頁面? – user2719875

+0

是的。我用在我的科爾多瓦應用程序(index.html) –

回答

1

您可以直接使用TemplateView

from django.views.generic import TemplateView 

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

記住,你需要configure your templates folder的名字只叫.html文件。

+0

好的新問題伴侶。我的所有資產(CSS/JS等)都坐在'app/www ...'中,而django無法找到它們。我如何使用靜態文件來克服這個問題? –

+1

在這裏你會找到你需要的配置:[靜態文件](https://docs.djangoproject.com/en/1.8/ref/settings/#static-files)。請注意使用完整路徑的示例。 – Gocht

+0

可悲的是我試過'STATIC_URL ='/ app/www /''和'STATICFILES_DIRS =( 「/ app/www」, )'但沒有任何工作 –

0

首先,將這個index.html頁面放在server/templates文件夾中,這樣Django就知道了。

然後,在你URLs.py做到這一點:

from django.views.generic import TemplateView 

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