我试图在我的Django应用程序中调用第三方API,更具体地说是在views.py
中。一旦我做了这个调用,Django就找不到模板base.html
基本上就是这样:
search_by_jobsite()
search_by_jobsite()
内部,对第三方API进行了调用,我将.pkl
文件的位置传递给API。位置是/webapp/camera_search/api/pickle/config.pkl
李>search_by_jobsite()
检索必要的信息render(request, 'siren_search.html', context)
。然而,这就是它失败的地方李>siren_search.html
中的第一行是{% extends 'base.html' %}
,因此它开始查找base.html
,但它在错误的目录中查找。当base.html
位于/webapp/webapp/templates/base.html
时,它正在/webapp/camera_search/api/pickle/
中搜索base.html
。出于某种原因,当django转到pickle/
文件夹将信息发送给第三方API时,它也开始在那里搜索base.html
,但它可以找到siren_search.html
,只需找到
django正在做的事情总结:
/webapp/camera_search/views.py
开始并进行第三方API调用/webapp/camera_search/api/pickle/
/webapp/camera_search/views.py
siren_search.html
,并在正确的位置/webapp/camera_search/templates/siren_search.html
找到它base.html
并在/webapp/camera_search/api/pickle/
中搜索,但它实际上位于/webapp/webapp/templates/base.html
李>以下是完整回溯的链接:http://dpaste.com/3ZTBJAG
我的问题是,发生了什么?我如何将Django重新路由回正确的目录
编辑:
这是我的模板设置和来自views.py
的相关代码
# /webapp/webapp/settings.py
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['webapp/templates/'],
'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',
],
},
},
]
# /webapp/camera_search/views.py
from .models import CameraSystem, JobSite
from django.core.exceptions import ObjectDoesNotExist
from django.shortcuts import render, redirect
from django.conf import settings
from zcrmsdk import ZCRMRecord, ZCRMRestClient, ZCRMModule
def siren_search(request):
term = request.GET.get('query', '')
context = {}
#
# ...
#
# Handle when the user presses enter
elif 'query' in request.GET and term != '' and not request.is_ajax():
try:
deployed = search_by_jobsite('JOBSITE') # --- This is what i'm attempting to do. Currently the search works using the below functionality, but i'm trying to integrate this third party API call.
jobsite = JobSite.objects.get(name__iexact=term)
cameras = jobsite.camerasystem_set.all()
context = {
'cameras': cameras,
}
except ObjectDoesNotExist:
context = {}
pass
return render(request, 'siren_search.html', context) # Django fails here
def search_by_jobsite(jobsite):
# config is a dictionary with API authentication settings.
config = settings.ZOHO_CONFIG
client = ZCRMRestClient.initialize(config)
all_cameras = ZCRMModule.get_instance('Vendors').search_records(f'{jobsite}')
deployed_cameras = {}
# ... process data
return deployed_cameras
下面是一个示例配置字典,我正在传递给API客户机
config = {
'sandbox': 'False',
'applicationLogFilePath': '/Users/user/Programming/suitee/webapp/camera_search/api/log/',
'client_id': 'xxxx.xxxxxxxxxxxxx',
'client_secret': 'xxxxxxxxxxxxxxxxxxxxxxxxx',
'redirect_uri': 'http://localhost:8000/',
'accounts_url': 'https://accounts.zoho.com',
'token_persistence_path': '/Users/user/Programming/suite/webapp/camera_search/api/pickle/',
'currentUserEmail': 'email@domain.com'
}
目前没有回答
相关问题 更多 >
编程相关推荐