Skip to main content

no me grava Problema al guardar en la base de datos djangoDjango con sqlite3SQlite3

PY

  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',)

 
 

HTML

{% block content %}
  <form action="/" method="POST">
  {% csrf_token %}
  {{ form.as_p }}
  <button type="submit">Agregar</button>
 </form>
 {% endblock content %}

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 %}
  <form action="/" method="POST">
  {% csrf_token %}
  {{ form.as_p }}
  <button type="submit">Agregar</button>
 </form>
 {% endblock content %}

Problema al guardar en base de datos Django con SQlite3

PY

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',)

HTML

{% block content %}
<form action="/" method="POST">
  {% csrf_token %}
  {{ form.as_p }}
  <button type="submit">Agregar</button>
</form>
{% endblock content %}
se añadieron 105 caracteres en el cuerpo
Origen Enlace
Igmer Rodriguez
  • 4.4k
  • 4
  • 24
  • 53

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 = [

  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):




 ]


 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 %}
  <form action="/" method="POST">
  {% csrf_token %}
  {{ form.as_p }}
  <button type="submit">Agregar</button>
 </form>
 {% endblock content %}

{% block content %}

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

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 %}
  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 %}
  <form action="/" method="POST">
  {% csrf_token %}
  {{ form.as_p }}
  <button type="submit">Agregar</button>
 </form>
 {% endblock content %}
Origen Enlace

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 %}