How do you render your form? Can I see the content of the template file?

Regards,

Aldian Fazrihady

On Mon, 24 Jun 2019, 20:14 Alexandru Caplat, <capla...@gmail.com> wrote:

> I have a form that in past works good but after I change some data in the 
> models and add image field it doesn't work.
>
> From admin I can add new records but I think is a problem with form id. When 
> I inspect in google chrome the admin page,
>
> form id is porumbei_form and when I inspect my template, the form id is not 
> showing.
>
> #My view @login_required(login_url='/login/')def porumbelnou(request):
>     if request.method == "POST":
>         form = AdaugaPorumbel(request.POST, request.FILES)
>         if form.is_valid():
>             form.save()
>             return HttpResponseRedirect('/porumbei/')
>     else:
>         form = AdaugaPorumbel()
>     context = {
>         'form': form,
>     }
>     template = loader.get_template("adaugare_porumbel.html")
>     return HttpResponse(template.render(context, request))
> #My formclass AdaugaPorumbel(forms.ModelForm):
>     class Meta:
>     model = Porumbei
>     fields = ['data_adaugare', 'serie_inel', 'anul', 'culoare', 'crescator', 
> 'culoare_ochi', 'sex', 'ecloziune',
>               'rasa', 'linie', 'nume', 'tata',
>               'mama', 'compartiment', 'status', 'data', 'vaccinat', 'info', 
> 'imagine', 'imagine_ochi']
>     widgets = {
>         'ecloziune': forms.DateInput(format='%d/%m/%Y',
>                                      attrs={'class': 'form-control', 'type': 
> 'date'}),
>         'data': forms.DateInput(format='%d/%m/%Y',
>                                 attrs={'class': 'form-control', 'type': 
> 'date'}),
>         'vaccinat': forms.DateInput(format='%d/%m/%Y',
>                                     attrs={'class': 'form-control', 'type': 
> 'date'}),
>
>         'info': forms.Textarea(attrs={'class': 'form-control mt-15', 'rows': 
> '3',
>                                       'placeholder': 'Vor apărea în 
> pedigree'}),
>     }
> #My model
> class Porumbei(models.Model):
>     id_porumbel = models.AutoField(primary_key=True)
>     data_adaugare = models.DateTimeField(default=datetime.now())
>     crescator = models.ForeignKey(settings.AUTH_USER_MODEL, 
> on_delete=models.CASCADE)
>     serie_inel = models.CharField(max_length=25, null=False, blank=False, 
> unique=True)
>     anul = models.CharField(max_length=4, null=False, blank=False)
>     culoare = models.ForeignKey(CuloriPorumbei, on_delete=models.CASCADE, 
> null=False, blank=False, )
>     culoare_ochi = models.ForeignKey(CuloriOchi, on_delete=models.CASCADE, 
> null<span class="pun" style="font-style: inherit; font-variant: inherit; 
> font-weigh
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAN7EoAZBaxyz8P-0oZ-52ajpy0R4d%3D_DvG7JdzARsDJTpWfuMQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to