Home > OS >  Error during template rendering using extra_context django
Error during template rendering using extra_context django

Time:12-03

Hello I'm using extra_context in views and in the HTML I'm passing it, but it seems that I am doing it wrong because I get this error: ProgrammingError at /informacion-tiendas/add column InformacionTiendas_informaciontiendas.nombre does not exist LINE 1: ...ECT "InformacionTiendas_informaciontiendas"."id", "Informaci...

And when commenting the extra_context line in views, the HTML page is already seen without errors, obviously the context does not pass and the inputs do not appear, but at least there are no errors

Does anyone know why?

views.py

class InformacionTiendasAdd(CreateView):
    model=InformacionTiendas
    form_class=InformacionTiendasForm
    template_name='InformacionTiendas/informacion-tiendas-agregar.html'
    success_url=reverse_lazy('InformacionTiendas:list_tiendas')
    extra_context={'tiendas': InformacionTiendas.objects.all()}

models.py

class InformacionTiendas(models.Model):
    nombre=models.CharField(max_length=255)
    registro_desde=models.DateTimeField(default=datetime.now )
    tax_id=models.IntegerField()
    
    def __str__(self):
        return f'{self.nombre} {self.registro_desde} {self.tax_id}'

informacion-agregar-tiendas.html


                                        <form class="needs-validation" novalidate>
                                            {% for tienda in tiendas %}
                                            <div class="row mb-3">
                                                <div class="col-md-12">
                                                    <div>
                                                        <label class="form-label" for="validationCustom01">Name</label>
                                                        {{ tienda.nombre }}
                                                        <div class="invalid-feedback">
                                                            Please provide the workshop name.
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="row">
                                                <div class="col-md-6">
                                                    <div class="mb-3">
                                                        <label class="form-label" for="validationCustom06">Registration</label>
                                                         {{ tienda.registro_desde }}
                                                            Please provide workshop`s registration number.
                                                        </div>
                                                    </div>
                                                </div>

                                                <div class="col-md-6">
                                                    <div class="mb-3">
                                                        <label class="form-label" for="validationCustom07">TAX ID</label>
                                                        {{ tienda.tax_id }}
                                                        <div class="invalid-feedback">
                                                            Please provide workshop`s registration number.
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            {% endfor %}
                                        </form>

CodePudding user response:

Based on the new information from your edit, it looks like you haven’t migrated the database.

Try running this in your shell:

python manage.py makemigrations
python manage.py migrate
  • Related