【发布时间】:2020-02-04 08:09:53
【问题描述】:
我的应用在 API 和模板之间解耦。我想知道将 API 与模板通信的方式。
我知道我可以通过 python manage.py collectstatic 将所有静态文件拉入 API 存储库,但我不想将 API 和模板结合到一个文件夹中。
我正在尝试从我的 django 应用程序访问静态文件到我的 django 应用程序之外的静态文件。我想将 UIUX/static 中的文件访问到 DjangoRepo/myapp/static。如下所示
UIUX/
- static
- staticfile...
- templates
- index.html
DjangoRepo/
- myapp
- static
- templates
我的观点.py
class IndexViewTemplateView(View):
# trying to acess the inedx.html file that is outside of Django file
template_name = '../../../UIUX/templates/index.html'
def get(self, request, *args, **kwargs):
return render(request, self.template_name)
def post(self, request, *args, **kwargs):
return render(request, self.template_name)
我根本没有为此编辑我的模板。 我需要做任何其他模板设置来存档吗?
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(PROJECT_ROOT, 'templates')],
# 'DIRS':[],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
# 'debug': DEBUG,
},
},
]
【问题讨论】:
标签: python django django-templates django-views