Do not insert data. from the input between django and postgres

0

catalog / urls.py

from django.urls import path
from catalogos.views import CategoriaView,CategoriaNew

urlpatterns =[
    .....

    path('categorias/new', CategoriaNew.as_view(),name='categoria_new'),

]

views.py

class CategoriaNew(generic.CreateView):
    model=Categoria
    template_name = "catalogos/categoria_form.html"
    context_object_name = 'obj'
    form_class=CategoriaForm
    success_url = reverse_lazy("catalogos:categoria_list")

form.py

from django import forms

from catalogos.models import  Categoria

class CategoriaForm(forms.ModelForm):
    class Meta:
        model=Categoria
        fields=['descripcion']
        labels= {'descripcion':'Descripcion de las categoria'},
        widget = {'descripcion':forms.TextInput()}

    def __init__(self,*args, **kwargs):
        super().__init__(*args, **kwargs)
        for field in iter(self.fields):
            self.fields[field].widget.attrs.update({
                'class':'form-control'
            })

template

{% extends 'base/base.html' %}

{% block contenido %}
    <form mehthod="POST">

        <div class="panel panel-default">
            <div class="panel panel-heading">
                    Editar/ crear categorias
            </div>

            <div class="panel-body">
                {% csrf_token %}
                {{ form.as_p }}
                <button type="submit" class="btn btn-danger"><span class="fa fa-save"></span> Guardar</button>
                <a href="{% url 'catalogos:categoria_list' %}" class="btn btn-success " ><span class="fa fa-undo">Cancelar</span></a>
            </div>
        </div>
    </form>

{% endblock contenido %}

catalog_list

<div class="panel panel-primary">
    <div class="panel-heading">
     <a href="{% url 'catalogos:categoria_new' %}" class="btn btn-info"><span class="fa fa-plus-circle"></span> Nueva</a>

    </div>
    <div class="panel-body">
        <table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-example">
            <thead>
                <tr>
                    <th>Id</th>
                    <th>Descripción</th>
                </tr>
            </thead>
            <tbody>
                {% for item in obj %}
                <tr>
                    <td>{{ item.id }}</td>
                    <td>{{ item.descripcion }}</td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
</div>
{% endblock contenido %}

view

  • Use: linux, postgres 10, django 2.0

    In the function reverse_lazy ("catalogos: category_list") it does not do the redirect, nor is it inserting the data in the table Any ideas to solve it?

asked by Developer 30.10.2018 в 18:17
source

1 answer

0

The solution is to correct the mehthod="POST" for method = 'POST' , I am using the pycharm editor when installing with

the psycopg2-binary , it works well the insertion of data

    
answered by 30.10.2018 / 21:49
source