Discussion:
unable to create modelform object in views
shiva kumar
2018-11-22 15:37:47 UTC
Permalink
views file

from django.core.mail import send_mail
from django.http import HttpResponse
# Create your views here.
from django.shortcuts import render,redirect
from django.urls import include
import datetime
from .forms import loginform,modelform
def hidemelogin(request):
if request.method == 'POST':
form=loginform(request.POST)
if form.is_valid():
subject = form.cleaned_data['your_name']
message = form.cleaned_data['message']
sender = form.cleaned_data['sender']
cc_myself = form.cleaned_data['cc_myself']
recipients = ['***@gmail.com']
if cc_myself:
recipients.append(sender)
print(subject, message,sender, cc_myself,recipients)
print(type(form))
return redirect('/hideme/blog/')
else :
form=loginform()
form1=modelform()
return render(request,'login.html',{'form':form,'form1':form1})
def hidemehtml(request):
print("shiva")
return render(request,'index.html',{})


model file

from django.db import models
class BlogPost(models.Model):
id=models.AutoField(primary_key=True)
yourname=models.CharField(max_length=20)
content=models.TextField(null=True,blank=True)
ccself=models.BooleanField(default=True)
sender=models.EmailField(blank=False)
def __str__(self):
return self.yourname
# Create your models here.


form file

from django import forms
from .models import BlogPost
class loginform(forms.Form):
your_name=forms.CharField(label='enter your name', max_length=100)
message = forms.CharField(widget=forms.Textarea)
sender = forms.EmailField()
cc_myself = forms.BooleanField(required=False)

class modelform(forms.ModelForm):
class meta:
model = BlogPost
fields=[
"id","name","message","sender","carbon copy"
]
--
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+***@googlegroups.com.
To post to this group, send email to django-***@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/CAMsYeuEwMsSZH6R27idvNm5yrokMo8qkQ1xOd19BpdwXW3%2BM%2Bw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Thiago Oliveira
2018-11-22 15:41:24 UTC
Permalink
what was the except is generator ?

Em qui, 22 de nov de 2018 às 13:38, shiva kumar <
Post by shiva kumar
views file
from django.core.mail import send_mail
from django.http import HttpResponse
# Create your views here.
from django.shortcuts import render,redirect
from django.urls import include
import datetime
from .forms import loginform,modelform
form=loginform(request.POST)
subject = form.cleaned_data['your_name']
message = form.cleaned_data['message']
sender = form.cleaned_data['sender']
cc_myself = form.cleaned_data['cc_myself']
recipients.append(sender)
print(subject, message,sender, cc_myself,recipients)
print(type(form))
return redirect('/hideme/blog/')
form=loginform()
form1=modelform()
return render(request,'login.html',{'form':form,'form1':form1})
print("shiva")
return render(request,'index.html',{})
model file
from django.db import models
id=models.AutoField(primary_key=True)
yourname=models.CharField(max_length=20)
content=models.TextField(null=True,blank=True)
ccself=models.BooleanField(default=True)
sender=models.EmailField(blank=False)
return self.yourname
# Create your models here.
form file
from django import forms
from .models import BlogPost
your_name=forms.CharField(label='enter your name', max_length=100)
message = forms.CharField(widget=forms.Textarea)
sender = forms.EmailField()
cc_myself = forms.BooleanField(required=False)
model = BlogPost
fields=[
"id","name","message","sender","carbon copy"
]
--
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
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/CAMsYeuEwMsSZH6R27idvNm5yrokMo8qkQ1xOd19BpdwXW3%2BM%2Bw%40mail.gmail.com
<https://groups.google.com/d/msgid/django-users/CAMsYeuEwMsSZH6R27idvNm5yrokMo8qkQ1xOd19BpdwXW3%2BM%2Bw%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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+***@googlegroups.com.
To post to this group, send email to django-***@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/CAGXgVz5naFivvBfAbYo15E1gFWhJ8VRXEoAO_3comZHUGkBMcA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Loading...