Am working on a web2py HTML view but keep getting an erros.
This is the code:
{{extend 'layout.html'}}
<h2>Edit your post</h2>
<h3>for category {{=form.record.category.name.title()}}</h3>
{{=form}}
and the error:
AttributeError: 'NoneType' object has no attribute 'name'
How can i fix the error?
N/B controller:
def edit_post():
id = post.id
form = SQLFORM(= A("Edit post",_href=URL(request.args=auth.user.id/login))
return locals()
Please see the SQLFORM documentation about how you create the form. I assume you've changed the code before you posted it up here, since python wouldn't compile it because of the = in the parameter list of SQLFORM.
Related
This question already has answers here:
Get the data received in a Flask request
(23 answers)
Closed 2 years ago.
I am trying to create a web application in Flask, but I keep getting the error:
'Request' object has no attribute 'Name' when sending data from a 'POST' form in my html. I have two submit buttons that I have to differentiate, and I wanted to do that by using their name, which I have previously done and it worked. This is the code from my HTML:
<input type = "submit" class="fadeIn second" value="Add this data." name = "add">
<input type = "submit" class="fadeIn second" value="Delete this data." name = "delete">
and this is where i am getting the error:
if request.method == 'POST' and request.Name=="add":
Can anyone help me out, please?
As the error states, a Request object does not have a "Name" attribute. You can access the name value with request.form.get("add"), for example.
See here for more examples.
Below is my code, which receiving an error
'QuerySet' object has no attribute 'zipCode'
def feeds_view(request):
profile = Profile.objects.filter(id=request.COOKIES['id'])
zipCode = profile.zipCode
when changing code to below receiving
'UserRegistration' object is not iterable:
def feeds_view(request):
user = Profile.objects.get(id=request.COOKIES['id'])
zipCode = user.zipCode
content = {
'user': user
}
return render(request, 'pages/feeds.html', content)
HTML Code:
<input type="text" name="feededBy" id="feededBy" value="{{user.displayName}}" hidden>
<input type="email" name="byEmailID" id="byEmailID" value="{{user.emailID}}" hidden>
Profile.objects.filter(id=request.COOKIES['id']) returns a QuerySet. To access the actual object, use list indexing, like profile[0].zipcode after getting value in profile. Since you are just expecting a single object, it is better to use get method or get_object_or_404 if applicable.
See this for introductory tutorial on this. You have to include more code for second error.
i am having this weird url reaction.
this is my views.py
def user_edit(request):
user = User.objects.get(id=request.GET.get('userid'))
return render_to_response("editprofile.html",{'user':user},context_instance=RequestContext(request))
and this is my form.
<form action="/update_userprofile/?userid={{user.id}}" ...
my urls.py
url(r'^update_userprofile/','home.views.update_userprofile')
but once i send the form, i am getting error:
Internal Server Error: /update_userprofile/on
where is that on coming from? i dont understand what happens here.
thanks a lot .
OK I try your codes. You did not put in your question what method did you use. So I try the GET and the output User matching query does not exist. I try the POST and it works now.
<form action="/update_userprofile/?userid={{user.id}}" method="POST">
Even though you have user id define in your url, you can still get the value from the method POST.
UPDATE:
You code is fine, just change the method into method=POST in your form
I want to send a mail to every user that fill a form on my django website. After writing a code for it, I'm getting the below error. I've been trying to find the cause of the error but no success. Below are my codes:
AttributeError at /meek/
'NoneType' object has no attribute 'e_mail'
Views
Subject='Welcome'
message=loader.get_template('letter.txt')
from_email='men#men.com'
def gent_me(request):
if request.method=='POST':
form=GentForm(request.POST)
if form.is_valid():
data=form.cleaned_data
newgent=Gent(
pub_date=datetime.datetime.now(),
full_name=data['full_name'],
company_name=data['company_name'],
services=data['services'],
e_mail=data['e_mail'],
address=data['address'],
city=data['city'],
state=data['state'],
phone_no=data['phone_no'])
invite=newgent.save()
send_mail(Subject, message.render(Context()),from_email,[invite.e_mail])
return HttpResponse('Thanks. Kindly check your mail.')
else:
return HttpResponse('Kindly fill form.')
else:
return render_to_response('ment.html',{'GentForm':GentForm},context_instance=RequestContext(request))
How can I fix this?
The Model.save method has a return value of 'None'. So 'invite' after invite=newgent.save() is None. Instead of
invite=newgent.save()
you should do
newgent.save()
and then
send_mail(Subject, message.render(Context()),from_email,[newgent.e_mail])
I'm getting this error in this function in my views.py file. It's confusing because I don't know what 'WSGIRequest' is or why it's giving me problems. I know I have a variable called "newUser" because when I take out that one line the print(request.POST) line prints it out.
def AddNewUser(request):
a=AMI()
if(request.method == "POST"):
print(request.POST)
print(request["newUser"])
csrfContext = RequestContext(request)
return render_to_response("ac/AddNewUser.html", csrfContext)
`
Why am I getting this error?
It means that WSGIRequest does not implement __getitem__. You are trying to treat the HttpRequest object like a dictionary but it's not. If you want to access this newUser variable use the POST object, which implements a dictionary-like interface:
request.POST['newUser']
You'd do well to peruse the Django docs in situations like this.