I
I
Ilya2016-02-09 10:52:50
Django
Ilya, 2016-02-09 10:52:50

Does anyone have an example of working with a form?

There are a lot of articles on the Internet, but not one at a time fails, maybe someone has a ready-made example of creating a form from a model. For django 1.9

class Start(models.Model):
  number_starts = model.IntegerField
  source = models.TextField

Here I am trying to make a form to add to the database, without an admin panel

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Gasoid, 2016-02-09
@nuBacuk

class StartForm(forms.ModelForm):
    class Meta:
        model = Start


def view_start(request):
    if request.method == "POST":
        form = StartForm(request.POST)
        if form.is_valid():
            form.save() # записывает данные в базу с формы
        else:
            # lalala
            return render(request, "form.html", {'form': form})
    else:
        form = StartForm()
    return render(request, "form.html", {'form': form})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question