[英]Separate front-end in django
我想将我的应用程序划分为Django项目中的前端和后端。 我的项目目录中有书籍应用程序,因此我将JS文件和index.html放置到myproject/books/front-end/
dir中。 现在,我只需要在视图中呈现index.html ,但为此必须在myproject/books/templates/
。 因此,我尝试使用render_to_response('../front-end/index.html')
舞蹈,但它只会呈现“无文件”错误。
PS Basic的想法是通过Handlebars处理所有模板工作,并使用RESTful API与Deliciouspie与服务器数据库进行通信。 也许这不是一个好主意,或者我做错了什么。
考虑在您的settings.py的TEMPLATES ['DIRS'] []列表中添加/ front-end /文件夹。 就像是
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'books/front-end/'),
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
#the usual stuff
],
},
},
]
在我的Django 1.8项目中,我有一些类似的东西。
在views.py中:
def desktop_view(request):
return render(request, 'index.html', {})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.