Ich mache einen AJAX-Aufruf und möchte ein Wörterbuch von Objekten zurückgeben. Egal, wie ich versuche, die Daten zurückzugeben, es löst eine Ausnahme aus. Soweit ich das beurteilen kann, kann es nur daran liegen, dass die Antwortdaten nicht im JSON-Format vorliegen.Wörterbuch aus AJAX-Aufruf mit Django zurückgeben
Jede Hilfe wäre wirklich
def populateSources(request):
if request.is_ajax():
try:
org = Organization.objects.get(pk=int(request.GET.get('org_id')))
std_source_columns = StandardizedSourceColumn.objects.all()
std_sources = StandardizedSource.objects.all()
# Standardized Tables API Client
std_tables_api_client = standardizedtablescli.ApiClient()
std_tables_api_client.host = os.environ.get('STANDARDIZED_ENDPOINT')
std_tables_api = standardizedtablescli.StandardizedtablesApi(std_tables_api_client)
org_std_sources = std_tables_api.get_standardized_tables_by_id(org.id)
ready_tables = std_tables_api.get_ready_raw_tables(org.id)
ready_table_mapping = dict()
ready_table_names = []
for table in ready_tables:
ready_table_names.append(table)
for key, value in org_std_sources.iteritems():
curr_source = StandardizedSource.objects.filter(name=key)
if len(value['standard_mappings']) == 0:
if key in ready_table_names:
ready_table_mapping[curr_source] = False
else:
ready_table_mapping[curr_source] = True
json_response = {}
json_response['result'] = ready_table_mapping
return HttpResponse(
json.dumps(json_response),
content_type="application/json"
)
except:
return HttpResponse(
json.dumps("error"),
content_type="application/json"
)
Was ist die Ausnahme? –
loswerden der Versuch ... außer Block. Sie werden wissen, was der Fehler ist. Außerdem ist es eine bd-Programmierpraxis, generische Ausnahmen auf solchen großen Codestücken zu fangen. – karthikr