Re: Help me with django Form

2012-01-13 Thread Python_Junkie
I believe you are mixing methods.

Django has built in generic views and generic forms for example.

But, you have used a template with standard (html) from syntax.

Since you are doing a post, request.

In your view just assign a variable to each variable in the form that
you are pulling back and then you can use those variables for the 2
functions that you wanted to achieve.

1. use the variables to insert a row into a database table
for example
names=request.names
etc

sql to insert into table
2. create a dcitionary to respond to the users request in the

[('names':names,   )]
 render_to_response('mainpage.html', dictionary values)


def welcome(request):
#Allow new user reg and login, if failed direct the user to
signup
if request.method=='POST':
form=models.Register()
new_user=form.save()
return HttpResponseRedirect('/logpage/')
else:
form=models.Register()
return render_to_response('mainpage.html',
{'form':models.Register})

On Jan 14, 12:13 am, coded kid  wrote:
> Thanks guys! @daniel I still don't get what django doc is trying to
> say about ModelForm. Can you please explain further?
>
> On Jan 12, 10:30 am, Daniel Roseman  wrote:
>
>
>
>
>
>
>
> > On Thursday, 12 January 2012 01:49:40 UTC, coded kid wrote:
>
> > > Hi guys, I’ve been trying to signup using the django form I created.
> > > Whenever I signup, the form is always saving the id no and not other
> > > fields like names, username.pasword,email etc. Below are the codes;
> > > In views.py:
> > > from django.shortcuts import render_to_response
> > > from django.http import HttpResponse
> > > from django.template import RequestContext
> > > from django.http import HttpResponseRedirect
> > > from mymeek.meekme import models
> > > from django.views.decorators.csrf import csrf_exempt
> > > @csrf_exempt
> > > def welcome(request):
> > >     #Allow new user reg and login, if failed direct the user to signup
> > >     if request.method=='POST':
> > >         form=models.Register()
> > >         new_user=form.save()
> > >         return HttpResponseRedirect('/logpage/')
> > >     else:
> > >         form=models.Register()
> > >         return render_to_response('mainpage.html',
> > > {'form':models.Register})
>
> > You haven't defined a form. Just calling a model instance "form" doesn't
> > make it one.
> > Plus, of course, at no point are you passing the POST values into the
> > instantiation.
> > Seehttps://docs.djangoproject.com/en/1.3/topics/forms/modelforms/for
> > modelforms,
> > andhttps://docs.djangoproject.com/en/1.3/topics/forms/#using-a-form-in-a...
> > for the general pattern of how to instantiate a form from the POST.
> > --
> > DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Help me with django Form

2012-01-13 Thread coded kid
Thanks guys! @daniel I still don't get what django doc is trying to
say about ModelForm. Can you please explain further?

On Jan 12, 10:30 am, Daniel Roseman  wrote:
> On Thursday, 12 January 2012 01:49:40 UTC, coded kid wrote:
>
> > Hi guys, I’ve been trying to signup using the django form I created.
> > Whenever I signup, the form is always saving the id no and not other
> > fields like names, username.pasword,email etc. Below are the codes;
> > In views.py:
> > from django.shortcuts import render_to_response
> > from django.http import HttpResponse
> > from django.template import RequestContext
> > from django.http import HttpResponseRedirect
> > from mymeek.meekme import models
> > from django.views.decorators.csrf import csrf_exempt
> > @csrf_exempt
> > def welcome(request):
> >     #Allow new user reg and login, if failed direct the user to signup
> >     if request.method=='POST':
> >         form=models.Register()
> >         new_user=form.save()
> >         return HttpResponseRedirect('/logpage/')
> >     else:
> >         form=models.Register()
> >         return render_to_response('mainpage.html',
> > {'form':models.Register})
>
> You haven't defined a form. Just calling a model instance "form" doesn't
> make it one.
> Plus, of course, at no point are you passing the POST values into the
> instantiation.
> Seehttps://docs.djangoproject.com/en/1.3/topics/forms/modelforms/for
> modelforms,
> andhttps://docs.djangoproject.com/en/1.3/topics/forms/#using-a-form-in-a...
> for the general pattern of how to instantiate a form from the POST.
> --
> DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Help me with django Form

2012-01-12 Thread Daniel Roseman
On Thursday, 12 January 2012 01:49:40 UTC, coded kid wrote:
>
> Hi guys, I’ve been trying to signup using the django form I created. 
> Whenever I signup, the form is always saving the id no and not other 
> fields like names, username.pasword,email etc. Below are the codes; 
> In views.py: 
> from django.shortcuts import render_to_response 
> from django.http import HttpResponse 
> from django.template import RequestContext 
> from django.http import HttpResponseRedirect 
> from mymeek.meekme import models 
> from django.views.decorators.csrf import csrf_exempt 
> @csrf_exempt 
> def welcome(request): 
> #Allow new user reg and login, if failed direct the user to signup 
> if request.method=='POST': 
> form=models.Register() 
> new_user=form.save() 
> return HttpResponseRedirect('/logpage/') 
> else: 
> form=models.Register() 
> return render_to_response('mainpage.html', 
> {'form':models.Register}) 
>
 
You haven't defined a form. Just calling a model instance "form" doesn't 
make it one.
Plus, of course, at no point are you passing the POST values into the 
instantiation.
See https://docs.djangoproject.com/en/1.3/topics/forms/modelforms/ for 
modelforms, 
and https://docs.djangoproject.com/en/1.3/topics/forms/#using-a-form-in-a-view 
for the general pattern of how to instantiate a form from the POST.
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/K8AJc--LKqIJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Help me with django Form

2012-01-11 Thread kenneth gonsalves
On Wed, 2012-01-11 at 17:49 -0800, coded kid wrote:
> Please where I’ve I done something wrong? Help me out!

you need to use ModelForm, not create your form in the template. Check
the docs on ModelForm.
-- 
regards
Kenneth Gonsalves

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Help me with django Form

2012-01-11 Thread Mario Gudelj
Can you provide your register model?

Is it possible that you've extended the user model and that your username,
password etc is getting stored inside auth_user table?


On 12 January 2012 12:49, coded kid  wrote:

> Hi guys, I’ve been trying to signup using the django form I created.
> Whenever I signup, the form is always saving the id no and not other
> fields like names, username.pasword,email etc. Below are the codes;
> In views.py:
> from django.shortcuts import render_to_response
> from django.http import HttpResponse
> from django.template import RequestContext
> from django.http import HttpResponseRedirect
> from mymeek.meekme import models
> from django.views.decorators.csrf import csrf_exempt
> @csrf_exempt
> def welcome(request):
>#Allow new user reg and login, if failed direct the user to signup
>if request.method=='POST':
>form=models.Register()
>new_user=form.save()
>return HttpResponseRedirect('/logpage/')
>else:
>form=models.Register()
>return render_to_response('mainpage.html',
> {'form':models.Register})
>
> In Models.py
> from django.db import models
> class Register(models.Model):
>names=models.CharField(max_length=50)
>email=models.EmailField('e-mail', blank=False)
>password=models.CharField(max_length=25)
>username=models.CharField(max_length=25)
>country=models.CharField(max_length=40)
>state_province=models.CharField(max_length=30)
>
>def __unicode__(self):
>return self.names
>
> In Template Form:
> 
>  {% csrf_token %}
> Names: 
> Email Address: 
> Password: 
> Username: 
> Country: 
> State: 
> 
> 
> 
> Please where I’ve I done something wrong? Help me out!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Help me with django Form

2012-01-11 Thread coded kid
Hi guys, I’ve been trying to signup using the django form I created.
Whenever I signup, the form is always saving the id no and not other
fields like names, username.pasword,email etc. Below are the codes;
In views.py:
from django.shortcuts import render_to_response
from django.http import HttpResponse
from django.template import RequestContext
from django.http import HttpResponseRedirect
from mymeek.meekme import models
from django.views.decorators.csrf import csrf_exempt
@csrf_exempt
def welcome(request):
#Allow new user reg and login, if failed direct the user to signup
if request.method=='POST':
form=models.Register()
new_user=form.save()
return HttpResponseRedirect('/logpage/')
else:
form=models.Register()
return render_to_response('mainpage.html',
{'form':models.Register})

In Models.py
from django.db import models
class Register(models.Model):
names=models.CharField(max_length=50)
email=models.EmailField('e-mail', blank=False)
password=models.CharField(max_length=25)
username=models.CharField(max_length=25)
country=models.CharField(max_length=40)
state_province=models.CharField(max_length=30)

def __unicode__(self):
return self.names

In Template Form:

 {% csrf_token %}
Names: 
Email Address: 
Password: 
Username: 
Country: 
State: 



Please where I’ve I done something wrong? Help me out!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Please help me with django form 2.

2012-01-11 Thread J. Cliff Dyer


On Tue, 2012-01-10 at 23:49 -0800, coded kid wrote:
> Hi guys, whenever I signup for my django form, my database is only
> saving the id no and not names, username, email etc. |  #sorry for
> posting it like this. I'm on mobile. Okay. In my views.py, this ( | )
> means next line.@csrf_exempt
> | def welcome(request): | if request.method=='POST': |
> form=models.Register() |new_user=form.save() | return
> HttpResponseRedirect('/logpage/') | else: |form=models.Register()|
> return render_to_response('mainpage.html', {'form':models.Register}) .
> I created an html form and a model with class Register(models.Model):
> 
> names=models.CharField(max_length=50) etc. I hope you get my point?
> Please help.
> 

Your code isn't working because you are saving a model without passing
any attributes to it.

form = model.Register()  # This isn't a form.  It's a model
form.save()  

This will create an empty model, and then when you save it, try to write
that empty model to the database, which will work only if all the fields
are nullable, and will give you a model object with all fields null,
except the primary key, which is automatically populated.

Instead you need to do something like this:

 form = model.Register(names=request.POST['names'])
 form.save()

But really, you should use django's ModelForm, and let django do the
heavy lifting for you.  The django docs can get you started.


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Please help me with django form 2.

2012-01-11 Thread 软刀
as I unflod your code
I think may be you should create a Form-class like this:
class RegisterForm(ModelForm):
class Meta:
model = Register


and in your view should be:
@csrf_exempt
def welcome(request):
if request.method=='POST':
form=RegisterForm(request.POST)
new_user=form.save()
return HttpResponseRedirect('/logpage/')
else:
form=RegisterForm()
return render_to_response('mainpage.html', {'form':form})


-- 
as I learning english, any help about english grammar is welcome

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Please help me with django form 2.

2012-01-11 Thread kenneth gonsalves
On Tue, 2012-01-10 at 23:49 -0800, coded kid wrote:
> names=models.CharField(max_length=50) etc. I hope you get my point?
> Please help. 

I would suggest that you get to a computer and post the full code.
Please help us to help you.
-- 
regards
Kenneth Gonsalves

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Please help me with django form 2.

2012-01-10 Thread coded kid
Hi guys, whenever I signup for my django form, my database is only
saving the id no and not names, username, email etc. |  #sorry for
posting it like this. I'm on mobile. Okay. In my views.py, this ( | )
means next line.@csrf_exempt
| def welcome(request): | if request.method=='POST': |
form=models.Register() |new_user=form.save() | return
HttpResponseRedirect('/logpage/') | else: |form=models.Register()|
return render_to_response('mainpage.html', {'form':models.Register}) .
I created an html form and a model with class Register(models.Model):

names=models.CharField(max_length=50) etc. I hope you get my point?
Please help.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Please help me with django form

2012-01-10 Thread kenneth gonsalves
On Tue, 2012-01-10 at 23:20 -0800, coded kid wrote:
> Hi guys, whenever I signup using the django form I created, my
> database is only saving the id no instead of username, email, first
> name etc. Please what should I do? 

please show us the relevant code
-- 
regards
Kenneth Gonsalves

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Please help me with django form

2012-01-10 Thread coded kid
Hi guys, whenever I signup using the django form I created, my
database is only saving the id no instead of username, email, first
name etc. Please what should I do?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.