Ejemplo n.º 1
0
def get_definitions(request):
    word = request.GET.get('word')
    definitions = definition(word)
    response_data = {}

    new_word = Word(text=word)
    if len(definitions) >= 1:
        new_word.definition1 = definitions[0]
    if len(definitions) >= 2:
        new_word.definition2 = definitions[1]
    if len(definitions) >= 3:
        new_word.definition3 = definitions[2]
    new_word.save()

    for i in range(len(definitions)):
        response_data[i] = definitions[i]

    return HttpResponse(json.dumps(response_data), content_type='application/json')