Skip to main content
1 de 3

no me grava en la base de datos django con sqlite3

from django.db import models

class Person(models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30)

from django.urls import path from .import views urlpatterns = [

path('', views.post_new, name='post_new'),

]

from django.shortcuts import render from .models import Person from .form import PostForm

def post_new(request): form = PostForm() return render(request, 'adm_coloegio/index.html', {'form': form}) if request.method == "POST": form = PostForm(request.POST) if form.is_valid(): post = form.save(commit=False) from django import forms

from .models import Person

class PostForm(forms.ModelForm):

class Meta:
   
    model =Person
    fields = ('first_name',  'last_name',)

{% block content %}

{% csrf_token %} {{ form.as_p }} Agregar {% endblock content %}