[Answer]-Insert data into tables from form django

1👍

forms.py

class RecipeForm(ModelForm):
    class Meta:
        model = Recipe

views.py

def create_recipe(request):
    if request.method == 'POST':
        form=RecipeForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('app_name:url_name'))
    return  render(request, 'create.html', {
        'form': RecipeForm(),
    })

html

<form action="/recipe/submit-recipe/" method="post">
    {% csrf_token %}
    {{form.as_p}}
    <input type="submit" value="OK">
</form>

Leave a comment