python - AttributeError at ....... 'NoneType' object has no attribute 'is_valid' while developing django model forms -
i error while saving modelform database.
"attributeerror @ /giris/markayenikaydet/, 'nonetype' object has no attribute is_valid "
what may cause ? stuck. related modelform generation or related not including ant function.
""""
model...
from __future__ import unicode_literals django.db import models datetime import datetime django.urls import reverse django.utils.translation import gettext _ class marka(models.model): marka_adi = models.charfield(max_length=200) def __str__(self): return(self.marka_adi)
url...
from django.views.generic import redirectview django.conf.urls import include, url . import views django.utils.translation import gettext _ urlpatterns = [ url(r'^$', views.index, name='index'), url(r'^demirbas/$', views.demirbaslistview.as_view(), name='demirbas'), url(r'^demirbas/(?p<pk>\d+)$', views.demirbasdetailview.as_view(), name='demirbas-detail'), url(r'^proje/$', views.projelistview.as_view(), name='proje'), url(r'^proje/(?p<pk>\d+)$', views.projedetailview.as_view(), name='proje-detail'), url(r'^marka/$', views.markalistview.as_view(), name='marka'), url(r'^marka/(?p<pk>\d+)$', views.markadetailview.as_view(), name='marka-detail'), url(r'^marka/duzeltsil/$', views.markaduzeltsil, name='markaduzeltsil'), url(r'^marka/ekle/$', views.markaekle, name='markaekle'), url(r'^kategori/$', views.kategorilistview.as_view(), name='kategori'), url(r'^kategori/(?p<pk>\d+)$', views.kategoridetailview.as_view(), name='kategori-detail'), url(r'^musteri/$', views.musterilistview.as_view(), name='musteri'), url(r'^musteri/(?p<pk>\d+)$', views.musteridetailview.as_view(), name='musteri-detail'), url(r'^marka/create/$', views.markacreate.as_view(), name='marka_create'), url(r'^marka/(?p<pk>\d+)/update/$', views.markaupdate.as_view(), name='marka_update'), url(r'^marka/(?p<pk>\d+)/delete/$', views.markadelete.as_view(), name='marka_delete'), url(r'^markayenikaydet/$', views.markayenikaydet, name='markayenikaydet'), ]
form....
from django import forms django.forms import modelform giris.models import marka django.utils.translation import gettext _ """from crispy_forms.helper import formhelper crispy_forms.layout import submit, layout, field crispy_forms.bootstrap import ( prependedtext, prependedappendedtext, formactions)""" def markagirisform(modelform): class meta: model = marka fields = '__all__' labels = { 'marka_adi': _('marka adı')} help_texts = { 'marka_adi': _('lüften marka adı giriniz..')}
view..
class markacreate(createview): model = marka fields = '__all__' class markaupdate(updateview): model = marka fields = '__all__' class markadelete(deleteview): model = marka success_url = reverse_lazy('marka_del') django.http import httpresponseredirect django.shortcuts import render .forms import markagirisform django.utils.translation import gettext _ def markayenikaydet(request): if request.method == 'post': form = markagirisform(request.post) if form.is_valid(): marka_ad_gecici = request.post.get('marka_adi') marka_obj = marka(marka_adi = marka_ad_gecici) marka.save() else: form = markagirisform() return render(request, '/giris/addbook.html', {'form': form})
template...
{% extends "base_generic.html" %} {% block content %} <form action="{% url 'markayenikaydet' %}" method="post"> {% csrf_token %} <table> {{ form.as_table }} </table> <input type="submit" value="kaydet" /> </form> {% endblock %}
Comments
Post a Comment