示例#1
0
def choose_ingredients(request):
    if request.method == 'POST':
        form = IngredientForm(request.POST)
        if form.is_valid():
            picked = form.cleaned_data.get('picked')
            ingredients = ''
            for ing in picked:
                ingredients += ing + '+'
    else:
        form = IngredientForm
        return render(request, 'choose_ingredients.html', {'form' : form})

    return redirect('/recipes/list/%s' % ingredients)
示例#2
0
def recipe_list(request):
    response = unirest.get("https://spoonacular-recipe-food-nutrition-v1.p.mashape.com/recipes/findByIngredients?ingredients=apples%2Cflour%2Csugar&number=5",
=======
def choose_ingredients(request):
    if request.method == 'POST':
        form = IngredientForm(request.POST)
        if form.is_valid():
            picked = form.cleaned_data.get('picked')
            ingredients = ''
            for ing in picked:
                ingredients += ing + '+'
    else:
        form = IngredientForm
        return render(request, 'choose_ingredients.html', {'form' : form})

    return redirect('/recipes/list/%s' % ingredients)

def recipe_list(request, ingredients):
    temp_ing = ingredients.split('+')
    search_string = ''
    for ingredient in temp_ing:
        search_string += ingredient + "%2C"

    search_string = search_string[:-6]
    print(search_string)

    response = unirest.get("https://spoonacular-recipe-food-nutrition-v1.p.mashape.com/recipes/findByIngredients?ingredients=" + search_string + "&number=10",
>>>>>>> be8d88bdb6587541493f2c93f91ebdbc8d0618eb
      headers={
        "X-Mashape-Key": "QN5CLcAiQXmshOrib4vl7QifQAPjp1MjXoijsnsKdgztp93FnI",
        "Accept": "application/json"
      }
    )

    context = {
<<<<<<< HEAD
        'response': response
    }

    return render(request, 'recipes_list.html', context)
=======
        'recipes': response,
        'ingredients': ingredients,
    }